-
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.
- Loading branch information
Showing
8 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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,11 @@ | ||
export const taskOne = { | ||
name: "Task one", | ||
description: "Task one description", | ||
_id: "6431bf51b21766f35002b58d" | ||
}; | ||
|
||
export const taskTwo = { | ||
name: "Task two", | ||
description: "Task two description", | ||
_id: "64328f8ca18a7ea4fc3f83b9" | ||
}; |
Empty file.
109 changes: 109 additions & 0 deletions
109
components/task/tests/public/respositories/task_respository.spec.ts
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,109 @@ | ||
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
import { TaskRepository } from "../../../public/repositories/task_repository"; | ||
import { taskOne, taskTwo } from "../../factories/tasks/task_data"; | ||
|
||
describe("Task Repository", () => { | ||
const sandbox = sinon.createSandbox(); | ||
let modelMock!: sinon.SinonStub<any[], any>; | ||
const taskRepository: TaskRepository = new TaskRepository(); | ||
|
||
before(() => { | ||
modelMock = sandbox.stub(); | ||
taskRepository.create = modelMock; | ||
taskRepository.read = modelMock; | ||
taskRepository.update = modelMock; | ||
taskRepository.delete = modelMock; | ||
}); | ||
|
||
describe("find()", () => { | ||
|
||
context("when present", () => { | ||
|
||
it("should find one task", async () => { | ||
const findOneMock = modelMock.returns(Promise.resolve(taskOne)); | ||
|
||
findOneMock.resolves(taskOne); | ||
|
||
const result = await taskRepository.read({ id: taskOne._id }); | ||
|
||
expect(result).to.deep.equal(taskOne); | ||
expect(modelMock.calledWith({})).to.be.true; | ||
}); | ||
}); | ||
|
||
it("should find list of tasks", async () => { | ||
const findMock = modelMock.returns(Promise.resolve([taskOne, taskTwo])); | ||
|
||
findMock.resolves([taskOne, taskTwo]); | ||
|
||
const result = await taskRepository.read({}); | ||
|
||
expect(result.length).to.equal(2); | ||
// TODO: this might be flaky | ||
expect(result[0]).to.deep.equal(taskOne); | ||
expect(findMock.calledWith({})).to.be.true; | ||
}); | ||
|
||
context("when not present", () => { | ||
it("should return empty array", async () => { | ||
const findOneMock = modelMock.returns(Promise.resolve([])); | ||
|
||
findOneMock.resolves([]); | ||
|
||
const result = await taskRepository.read({ id: taskOne._id }); | ||
|
||
expect(result).to.be.empty; | ||
expect(modelMock.calledWith({})).to.be.true; | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe("should create a task", async () => { | ||
const createMock = modelMock.returns(Promise.resolve(taskOne)); | ||
|
||
createMock.resolves(taskOne); | ||
|
||
const result = await taskRepository.create({ | ||
name: taskOne.name, | ||
description: taskOne.description | ||
}); | ||
|
||
expect(result).to.deep.equal(taskOne); | ||
}); | ||
|
||
it("should update a task", async () => { | ||
const updateMock = modelMock.returns(Promise.resolve(taskTwo)); | ||
updateMock.resolves(taskTwo); | ||
|
||
const result = await taskRepository.update({ | ||
id: taskOne._id, | ||
name: taskTwo.name, | ||
description: taskTwo.description | ||
}); | ||
|
||
expect({ | ||
name: result.name, | ||
description: result.description | ||
}).to.deep.equal({ | ||
name: taskTwo.name, | ||
description: taskTwo.description | ||
}); | ||
}); | ||
|
||
it("should delete a task", async () => { | ||
const deleteMock = modelMock.returns(Promise.resolve(undefined)); | ||
|
||
deleteMock.resolves(undefined); | ||
const result = await taskRepository.delete({ id: taskOne._id }); | ||
|
||
expect(result).to.equal(undefined); | ||
}); | ||
|
||
// Tear down | ||
afterEach(() => { | ||
sinon.restore(); | ||
sandbox.restore(); | ||
}); | ||
}); |
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
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