-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbe7ec3
commit a01b696
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../server/test/workspaces/resources.test.ts → code/server/test/resources/resources.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', | ||
}; | ||
await services.users.createUser(id, userData); | ||
const user = await services.users.getUser(id); | ||
expect(user.name).toEqual('test'); | ||
expect(user.email).toEqual('[email protected]'); | ||
}); | ||
|
||
test('should update a user', async () => { | ||
const id = getRandomUserId(); | ||
const userData = { | ||
name: 'test', | ||
email: '[email protected]', | ||
}; | ||
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: '[email protected]', | ||
}; | ||
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: '[email protected]', | ||
}; | ||
const id2 = getRandomUserId(); | ||
const user2Data = { | ||
name: 'test2', | ||
email: '[email protected]', | ||
}; | ||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getRandomUserId() { | ||
return Math.random().toString(36).substring(2, 30); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', | ||
}; | ||
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: '[email protected]', | ||
}; | ||
|
||
// 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); | ||
}); | ||
}); |