Skip to content

Commit

Permalink
fetchAllTipsの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
fortegp05 committed Apr 30, 2019
1 parent e644712 commit 0a81405
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/domains/tips.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addTips, TipsRepositoryPort } from "./tips";
import { addTips, TipsRepositoryPort, TipsPort, fetchAllTips } from "./tips";

describe("addTips", () => {
test("IDが生成されて、saveされる", () => {
Expand All @@ -14,3 +14,28 @@ describe("addTips", () => {
expect(save.mock.calls[0][1]).toBe("fugafuga");
});
});

describe("fetchAllTips", () => {
test("すべてのTipsを取得してTipsPortにセットする", async () => {
const expectValue = [{
id: "hoge",
message: "fuga"
}];
const findAll = jest.fn().mockImplementation(() => {
return expectValue
});
const tipsRepositoryPort: TipsRepositoryPort = {
save: jest.fn(),
findAll,
findById: jest.fn()
}
const setAllTips = jest.fn();
const tipsPort: TipsPort = {
setAllTips
}

await fetchAllTips(tipsRepositoryPort, tipsPort);
expect(setAllTips.mock.calls.length).toBe(1);
expect(setAllTips.mock.calls[0][0]).toEqual(expectValue);
})
})
14 changes: 14 additions & 0 deletions src/domains/tips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface TipsRepositoryPort {
findAll: () => Promise<Tips[]>;
}

export interface TipsPort {
setAllTips: (allTips: Tips[]) => void;
}

const createId = () => "hoge";

export const addTips = (
Expand All @@ -19,4 +23,14 @@ export const addTips = (
tipsRepositoryPort.save(createId(), message);
};

export const fetchAllTips = async (
tipsRepositoryPort: TipsRepositoryPort,
tipsPort: TipsPort
) => {
const allTips = await tipsRepositoryPort.findAll();
tipsPort.setAllTips(allTips);
};



// export const updateTips = (id: string, message: string)

0 comments on commit 0a81405

Please sign in to comment.