-
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.
finish ts stuff, add test files, add tests for userstore
- Loading branch information
Showing
5 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes.
Empty file.
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,66 @@ | ||
// userStore.test.ts | ||
|
||
import { get } from 'svelte/store'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { addUser, removeUser, type UserData, users } from './userStore'; | ||
|
||
// Mock user data | ||
|
||
// Test suite for userStore | ||
describe('test_normal_function', () => { | ||
const mockUserToken = 'mockUserToken'; | ||
const mockUserData: UserData = { | ||
role: 'mockRole', | ||
email: 'mockEmail', | ||
name: 'mockName', | ||
token: '', | ||
password: 'mockPassword', | ||
data: { | ||
yearofbirth: 1990, | ||
gender: 'male', | ||
profession: 'developer', | ||
education: 'bachelor', | ||
workinghours: 'full-time', | ||
householdincome: 'above-average' | ||
} | ||
}; | ||
|
||
it('should add a new user successfully', async () => { | ||
users.set({}); | ||
|
||
await addUser(mockUserToken, mockUserData); | ||
|
||
expect(get(users)[mockUserToken]).toEqual({ | ||
...mockUserData, | ||
token: mockUserToken | ||
}); | ||
}); | ||
|
||
it('should not add a user with an existing token', async () => { | ||
users.set({ mockUserToken: mockUserData }); | ||
|
||
try { | ||
await addUser(mockUserToken, mockUserData); | ||
} catch (error: Error | unknown) { | ||
expect((error as Error).message).toBe('User with this token already exists'); | ||
} | ||
}); | ||
|
||
it('should remove a user successfully', async () => { | ||
users.set({ mockUserToken: mockUserData }); | ||
|
||
await removeUser(mockUserToken); | ||
|
||
expect(get(users)[mockUserToken]).toBeUndefined(); | ||
}); | ||
|
||
it('should not remove a user with a non-existing token', async () => { | ||
users.set({ mockUserToken: mockUserData }); | ||
|
||
try { | ||
await removeUser('notdefined'); | ||
} catch (error: Error | unknown) { | ||
expect((error as Error).message).toBe('User with this token does not exist'); | ||
} | ||
}); | ||
}); |
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