From d79fc7be018f40f79a6f0b456bdc8544ef10e5a6 Mon Sep 17 00:00:00 2001 From: mytharcher Date: Sat, 21 Oct 2023 17:38:03 +0800 Subject: [PATCH] test(plugin-users): add test cases --- .../src/server/__tests__/fields.test.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/packages/plugins/@nocobase/plugin-users/src/server/__tests__/fields.test.ts b/packages/plugins/@nocobase/plugin-users/src/server/__tests__/fields.test.ts index 391c27408e..9dad83e4f5 100644 --- a/packages/plugins/@nocobase/plugin-users/src/server/__tests__/fields.test.ts +++ b/packages/plugins/@nocobase/plugin-users/src/server/__tests__/fields.test.ts @@ -86,5 +86,77 @@ describe('createdBy/updatedBy', () => { expect(data.createdBy.id).toBe(user1.get('id')); expect(data.updatedBy.id).toBe(user2.get('id')); }); + + it('input with createdById', async () => { + const Post = db.collection({ + name: 'posts', + createdBy: true, + updatedBy: true, + }); + await db.sync(); + + const u1 = await db.getCollection('users').model.create(); + const p1 = await Post.repository.create({ + values: { + createdById: u1.id, + }, + }); + + expect(p1.get('createdById')).toBe(u1.id); + }); + + it.skip('input with createdBy', async () => { + const Post = db.collection({ + name: 'posts', + createdBy: true, + updatedBy: true, + }); + await db.sync(); + + const u1 = await db.getCollection('users').model.create(); + const p1 = await Post.repository.create({ + values: { + createdBy: u1.id, + }, + }); + + expect(p1.get('createdById')).toBe(u1.id); + }); + + it.skip('input with updatedById', async () => { + const Post = db.collection({ + name: 'posts', + createdBy: true, + updatedBy: true, + }); + await db.sync(); + + const u1 = await db.getCollection('users').model.create(); + const p1 = await Post.repository.create({ + values: { + updatedById: u1.id, + }, + }); + + expect(p1.get('updatedById')).toBe(u1.id); + }); + + it.skip('input with updatedBy', async () => { + const Post = db.collection({ + name: 'posts', + createdBy: true, + updatedBy: true, + }); + await db.sync(); + + const u1 = await db.getCollection('users').model.create(); + const p1 = await Post.repository.create({ + values: { + updatedBy: u1.id, + }, + }); + + expect(p1.get('updatedById')).toBe(u1.id); + }); }); });