Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option, add time of done to record
- Loading branch information
1 parent
8d4ee6a
commit 64a95f2
Showing
11 changed files
with
375 additions
and
4 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
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,92 @@ | ||
/* eslint-disable no-loop-func */ | ||
import { Trekin } from "../Trekin"; | ||
import { Action } from "../Trello"; | ||
import fs from "fs"; | ||
import { Worker } from "../Worker"; | ||
import { KintoneRestAPIClient } from "@kintone/rest-api-client"; | ||
import { SettingGuardian } from "../Setting"; | ||
import { ApiExecutor } from "../ApiExecutor"; | ||
const JSON5 = require("json5"); | ||
|
||
jest.mock("@kintone/rest-api-client"); | ||
const KintoneMock = (KintoneRestAPIClient as unknown) as jest.Mock; | ||
|
||
jest.mock("../ApiExecutor"); | ||
const getRecordIdFromCardMock = (ApiExecutor.getRecordIdFromCard as unknown) as jest.Mock; | ||
const addTimeOfDoneToRecordMock = (ApiExecutor.addTimeOfDoneToRecord as unknown) as jest.Mock; | ||
|
||
const createWorker = () => { | ||
const w = new Worker( | ||
{ | ||
baseUrl: "", | ||
cards: { id: "", token: "" }, | ||
defaultKintoneUserCode: "", | ||
labels: { id: "", token: "" }, | ||
lists: { id: "", token: "" }, | ||
members: { id: "", token: "" }, | ||
}, | ||
{ apiKey: "", apiToken: "" } | ||
); | ||
|
||
return w; | ||
}; | ||
|
||
describe("addTimeOfDoneToRecordのテスト", () => { | ||
const testcases = [ | ||
{ | ||
name: "変更日時を取得できる", | ||
input: { | ||
actionPath: "./src/__tests__/trello_events/updateCard_idList_3.json", | ||
settingPath: | ||
"./src/__tests__/trekin_settings/enableAddDoneTime_1.trekinrc.json5", | ||
}, | ||
expected: "2020-07-31T02:53:23.814Z", | ||
}, | ||
{ | ||
name: "doneじゃないのでスキップする", | ||
input: { | ||
actionPath: "./src/__tests__/trello_events/updateCard_idList_1.json", | ||
settingPath: | ||
"./src/__tests__/trekin_settings/enableAddDoneTime_1.trekinrc.json5", | ||
}, | ||
expected: "Skip addTimeOfDoneToRecord", | ||
}, | ||
{ | ||
name: "リスト移動じゃないのでスキップする", | ||
input: { | ||
actionPath: "./src/__tests__/trello_events/createCard_1.json", | ||
settingPath: | ||
"./src/__tests__/trekin_settings/enableAddDoneTime_1.trekinrc.json5", | ||
}, | ||
expected: "Skip addTimeOfDoneToRecord", | ||
}, | ||
]; | ||
|
||
for (const { name, input, expected } of testcases) { | ||
test(name, async () => { | ||
KintoneMock.mockImplementation(() => { | ||
return true; | ||
}); | ||
getRecordIdFromCardMock.mockImplementation(() => { | ||
return "1"; | ||
}); | ||
addTimeOfDoneToRecordMock.mockImplementation( | ||
(_client, _cardId, _recordId, doneTime) => { | ||
return doneTime; | ||
} | ||
); | ||
|
||
const w = await createWorker(); | ||
w.setting = new SettingGuardian( | ||
JSON5.parse(fs.readFileSync(input.settingPath, "utf-8")) | ||
); | ||
const action: Action = JSON.parse( | ||
await fs.readFileSync(input.actionPath, "utf8") | ||
).body.action; | ||
w.trelloAction = action; | ||
|
||
const actual = await w.addTimeOfDoneToRecord(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
} | ||
}); |
4 changes: 4 additions & 0 deletions
4
src/__tests__/trekin_settings/enableAddDoneTime_1.trekinrc.json5
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,4 @@ | ||
{ | ||
isAddDoneTime: true, | ||
doneListName: "Done🎉" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/__tests__/trekin_settings/enableAddDoneTime_2.trekinrc.json5
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,3 @@ | ||
{ | ||
isAddDoneTime: true, | ||
} |
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,77 @@ | ||
{ | ||
"body": { | ||
"action": { | ||
"id": "5f2387a3dfc88d4d3f6d23ae", | ||
"idMemberCreator": "5ecb263b62993c0d35798ec6", | ||
"data": { | ||
"old": { | ||
"name": "oldName", | ||
"idList": "oldIdList" | ||
}, | ||
"card": { | ||
"idList": "newIdList", | ||
"id": "newId", | ||
"name": "これは新しいカードです!!", | ||
"idShort": 27, | ||
"shortLink": "hBE7fh7c" | ||
}, | ||
"board": { | ||
"id": "5f02821bf3e65f322beb3ea4", | ||
"name": "trello APIテスト", | ||
"shortLink": "Sqsia9EM" | ||
}, | ||
"listBefore": { | ||
"id": "5f237f512144fd2c583ae3f4", | ||
"name": "fffff" | ||
}, | ||
"listAfter": { | ||
"id": "5f1e8b1ed6438e403c6f18fe", | ||
"name": "Done🎉" | ||
} | ||
}, | ||
"type": "updateCard", | ||
"date": "2020-07-31T02:53:23.814Z", | ||
"limits": {}, | ||
"display": { | ||
"translationKey": "action_move_card_from_list_to_list", | ||
"entities": { | ||
"card": { | ||
"type": "card", | ||
"idList": "5f1e8b1ed6438e403c6f18fe", | ||
"id": "5f237f64ff024f3a01851dc9", | ||
"shortLink": "hBE7fh7c", | ||
"text": "fffffリスト" | ||
}, | ||
"listBefore": { | ||
"type": "list", | ||
"id": "5f237f512144fd2c583ae3f4", | ||
"text": "fffff" | ||
}, | ||
"listAfter": { | ||
"type": "list", | ||
"id": "5f1e8b1ed6438e403c6f18fe", | ||
"text": "aaaaa" | ||
}, | ||
"memberCreator": { | ||
"type": "member", | ||
"id": "5ecb263b62993c0d35798ec6", | ||
"username": "korosuke613", | ||
"text": "Futa Hirakoba (平木場 風太)" | ||
} | ||
} | ||
}, | ||
"memberCreator": { | ||
"id": "5ecb263b62993c0d35798ec6", | ||
"username": "korosuke613", | ||
"activityBlocked": false, | ||
"avatarHash": "afe1dce94ee1d794699a96d03c560dee", | ||
"avatarUrl": "https://trello-members.s3.amazonaws.com/5ecb263b62993c0d35798ec6/afe1dce94ee1d794699a96d03c560dee", | ||
"fullName": "Futa Hirakoba", | ||
"idMemberReferrer": "5e82ef3619774982716eb912", | ||
"initials": "FH", | ||
"nonPublic": {}, | ||
"nonPublicAvailable": true | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.