-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientStorage.infra.ts
40 lines (35 loc) · 1.3 KB
/
clientStorage.infra.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ClientStorageRepository } from "../../modules/journal/clientStorageRepository.ts";
import { InMemoryClientStorage } from "../../modules/journal/infra/repos/inMemoryClientStorage.ts";
import { LocalStorageClient } from "../../modules/journal/infra/repos/localStorageClient.ts";
import { Journal } from "../../modules/journal/journal.ts";
describe('Client Storage Contract Test', () => {
let repos: ClientStorageRepository[] = [];
const journal = Journal.create({
title: 'Take out the trash'
});
beforeEach(() => {
repos = [
new InMemoryClientStorage(),
new LocalStorageClient(),
];
});
it('Can save a journal entry', async () => {
for (const repo of repos) {
await repo.add(journal);
const entries = await repo.getAll();
expect(entries[0].title).toEqual('Take out the trash');
expect(entries[0].id).toEqual(journal.getId());
}
});
it('Can delete a journal entry', async () => {
for (const repo of repos) {
await repo.add(journal);
const entries = await repo.getAll();
expect(entries[0].title).toEqual('Take out the trash');
expect(entries[0].id).toEqual(journal.getId());
await repo.delete(journal.getId());
const newEntries = await repo.getAll();
expect(newEntries.length).toBe(0);
}
})
});