-
Notifications
You must be signed in to change notification settings - Fork 1
/
adapter.test.ts
24 lines (20 loc) · 954 Bytes
/
adapter.test.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
import { AdaptToNewDatabase, OldDatabase } from "./adapter"
const mockOldDatabase: OldDatabase = {
create: jest.fn(),
update: jest.fn(),
has: jest.fn(),
}
describe("OldDatabase to NewDatabase Adapter", () => {
const oldDatabaseUpdateSpy = jest.spyOn(mockOldDatabase, "update")
const oldDatabaseCreateSpy = jest.spyOn(mockOldDatabase, "create")
const adapted = AdaptToNewDatabase(mockOldDatabase)
it("Should execute create method of old database class if database has entry with given id", () => {
adapted.upsert({ id: "1", post: "test" })
expect(oldDatabaseCreateSpy).toHaveBeenCalledWith({ id: "1", post: "test" })
})
it("Should execute update method of old database class if database entry with given id doesn't exists", () => {
mockOldDatabase.has = jest.fn().mockReturnValue(true)
adapted.upsert({ id: "1", post: "test" })
expect(oldDatabaseUpdateSpy).toHaveBeenCalledWith({ id: "1", post: "test" })
})
})