|
|
|
@ -1,5 +1,5 @@ |
|
|
|
require("../../../tests/utilities/TestConfiguration") |
|
|
|
const { get, put } = require("../writethrough") |
|
|
|
const { Writethrough } = require("../writethrough") |
|
|
|
const { dangerousGetDB } = require("../../db") |
|
|
|
const tk = require("timekeeper") |
|
|
|
|
|
|
|
@ -9,20 +9,20 @@ tk.freeze(START_DATE) |
|
|
|
const DELAY = 5000 |
|
|
|
|
|
|
|
const db = dangerousGetDB("test") |
|
|
|
const writethrough = new Writethrough(db) |
|
|
|
|
|
|
|
describe("writethrough", () => { |
|
|
|
|
|
|
|
describe("put", () => { |
|
|
|
let first |
|
|
|
it("should be able to store, will go to DB", async () => { |
|
|
|
const response = await put(db,{ _id: "test", value: 1 }, DELAY) |
|
|
|
const response = await writethrough.put({ _id: "test", value: 1 }, DELAY) |
|
|
|
const output = await db.get(response._id) |
|
|
|
first = output |
|
|
|
expect(output.value).toBe(1) |
|
|
|
}) |
|
|
|
|
|
|
|
it("second put shouldn't update DB", async () => { |
|
|
|
const response = await put(db, { ...first, value: 2 }, DELAY) |
|
|
|
const response = await writethrough.put({ ...first, value: 2 }, DELAY) |
|
|
|
const output = await db.get(response._id) |
|
|
|
expect(first._rev).toBe(output._rev) |
|
|
|
expect(output.value).toBe(1) |
|
|
|
@ -30,7 +30,7 @@ describe("writethrough", () => { |
|
|
|
|
|
|
|
it("should put it again after delay period", async () => { |
|
|
|
tk.freeze(START_DATE + DELAY + 1) |
|
|
|
const response = await put(db, { ...first, value: 3 }, DELAY) |
|
|
|
const response = await writethrough.put({ ...first, value: 3 }, DELAY) |
|
|
|
const output = await db.get(response._id) |
|
|
|
expect(response._rev).not.toBe(first._rev) |
|
|
|
expect(output.value).toBe(3) |
|
|
|
@ -39,7 +39,7 @@ describe("writethrough", () => { |
|
|
|
|
|
|
|
describe("get", () => { |
|
|
|
it("should be able to retrieve", async () => { |
|
|
|
const response = await get(db, "test") |
|
|
|
const response = await writethrough.get("test") |
|
|
|
expect(response.value).toBe(3) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|