diff --git a/code/server/test/workspaces/resources.test.ts b/code/server/test/resources/resources.test.ts similarity index 97% rename from code/server/test/workspaces/resources.test.ts rename to code/server/test/resources/resources.test.ts index 8bc9b69a..73c39548 100644 --- a/code/server/test/workspaces/resources.test.ts +++ b/code/server/test/resources/resources.test.ts @@ -1,7 +1,7 @@ import { TestDatabases } from '../../src/databases/TestDatabases'; import { Services } from '../../src/services/Services'; import { ResourceType } from '@notespace/shared/src/workspace/types/resource'; -import { excludeRoot } from './utils'; +import { excludeRoot } from '../workspaces/utils'; let services: Services; diff --git a/code/server/test/users/authentication.test.ts b/code/server/test/users/authentication.test.ts new file mode 100644 index 00000000..84828875 --- /dev/null +++ b/code/server/test/users/authentication.test.ts @@ -0,0 +1,8 @@ +// implement integration tests for user authentication using firebase auth sdk + +describe('User authentication', () => { + test('should register a user', async () => { + // TODO + expect(true).toBe(true); + }); +}); diff --git a/code/server/test/users/users.test.ts b/code/server/test/users/users.test.ts new file mode 100644 index 00000000..10e6bca6 --- /dev/null +++ b/code/server/test/users/users.test.ts @@ -0,0 +1,65 @@ +import { TestDatabases } from '../../src/databases/TestDatabases'; +import { Services } from '../../src/services/Services'; +import { getRandomUserId } from './utils'; +import { User } from '@notespace/shared/src/users/types'; + +let services: Services; + +beforeEach(() => { + services = new Services(new TestDatabases()); +}); + +describe('User operations', () => { + test('should create a user', async () => { + const id = getRandomUserId(); + const userData = { + name: 'test', + email: 'test@test.com', + }; + await services.users.createUser(id, userData); + const user = await services.users.getUser(id); + expect(user.name).toEqual('test'); + expect(user.email).toEqual('test@test.com'); + }); + + test('should update a user', async () => { + const id = getRandomUserId(); + const userData = { + name: 'test', + email: 'test@test.com', + }; + await services.users.createUser(id, userData); + await services.users.updateUser(id, { name: 'test2' }); + const user = await services.users.getUser(id); + expect(user.name).toEqual('test2'); + }); + + test('should delete a user', async () => { + const id = getRandomUserId(); + const userData = { + name: 'test', + email: 'test@test.com', + }; + await services.users.createUser(id, userData); + await services.users.deleteUser(id); + await expect(services.users.getUser(id)).rejects.toThrow('User not found'); + }); + + test('should get all users', async () => { + const id1 = getRandomUserId(); + const user1Data = { + name: 'test1', + email: 'test1@test.com', + }; + const id2 = getRandomUserId(); + const user2Data = { + name: 'test2', + email: 'test2@test.com', + }; + await services.users.createUser(id1, user1Data); + await services.users.createUser(id2, user2Data); + const users: User[] = await services.users.getUsers(); + expect(users.some(u => u.id === id1)).toBe(true); + expect(users.some(u => u.id === id2)).toBe(true); + }); +}); diff --git a/code/server/test/users/utils.ts b/code/server/test/users/utils.ts new file mode 100644 index 00000000..2002b8d3 --- /dev/null +++ b/code/server/test/users/utils.ts @@ -0,0 +1,3 @@ +export function getRandomUserId() { + return Math.random().toString(36).substring(2, 30); +} diff --git a/code/server/test/workspaces/members.test.ts b/code/server/test/workspaces/members.test.ts new file mode 100644 index 00000000..0810b673 --- /dev/null +++ b/code/server/test/workspaces/members.test.ts @@ -0,0 +1,44 @@ +import { TestDatabases } from '../../src/databases/TestDatabases'; +import { Services } from '../../src/services/Services'; +import { getRandomUserId } from '../users/utils'; + +let services: Services; + +beforeEach(() => { + services = new Services(new TestDatabases()); +}); + +describe('Workspace members operations', () => { + test('should add a member to a workspace', async () => { + const wid = await services.workspaces.createWorkspace('test', false); + const userId = getRandomUserId(); + const userData = { + name: 'test', + email: 'test@test.com', + }; + await services.users.createUser(userId, userData); + await services.workspaces.addWorkspaceMember(wid, userData.email); + const workspace = await services.workspaces.getWorkspace(wid); + expect(workspace.members).toContain(userData.email); + }); + + test('should remove a member from a workspace', async () => { + const wid = await services.workspaces.createWorkspace('test', false); + const userId = getRandomUserId(); + const userData = { + name: 'test', + email: 'test@test.com', + }; + + // add user to workspace + await services.users.createUser(userId, userData); + await services.workspaces.addWorkspaceMember(wid, userData.email); + const workspace = await services.workspaces.getWorkspace(wid); + expect(workspace.members).toContain(userData.email); + + // remove user from workspace + await services.workspaces.removeWorkspaceMember(wid, userData.email); + const workspaceAfter = await services.workspaces.getWorkspace(wid); + expect(workspaceAfter.members).not.toContain(userData.email); + }); +});