Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaHaWo committed Aug 27, 2024
1 parent 84473ff commit 1f1b6c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/lib/stores/childrenStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
addChildData,
addChildObservation,
children,
fetchChildData,
fetchObservationData,
removeChildData,
type ChildObject,
type ChildrenList,
Expand Down Expand Up @@ -125,4 +127,40 @@ describe('normal functionality', () => {
expect((error as Error).message).toBe('Child token notthere not found for user token alpha');
}
});

it('should fetch observation data', async () => {
children.set(mockChildList);
expect(await fetchObservationData('alpha', 'childA')).toEqual(mockObservationData);
});

it('should fetch child data', async () => {
children.set(mockChildList);
expect(await fetchChildData('alpha', 'childA')).toEqual({
name: 'foo',
age: 3,
nationality: 'turkish'
});
});

it('cannot fetch from uknown keys', async () => {
children.set(mockChildList);

try {
await fetchObservationData('x', 'childA');
} catch (error: Error | unknown) {
expect((error as Error).message).toBe('No such user in the childrenstore');
}

try {
await fetchObservationData('alpha', 'unknown');
} catch (error: Error | unknown) {
expect((error as Error).message).toBe('No such child in the childrenstore for user alpha');
}
});

it('should fetch list of childrendata', async () => {});

it('cannot fetch childrendata from uknown', async () => {});

it('cannot fetch observationdata from uknown', async () => {});
});
2 changes: 1 addition & 1 deletion src/lib/stores/childrenStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function fetchObservationData(usertoken: string, childtoken: string) {
}

if (!(childtoken in contentData[usertoken as keyof ChildrenList])) {
throw new Error('No such child in the childrenstore for user' + usertoken);
throw new Error('No such child in the childrenstore for user ' + usertoken);
}

return contentData[usertoken as keyof ChildrenList][childtoken].observationData;
Expand Down

0 comments on commit 1f1b6c1

Please sign in to comment.