-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
00ffa59
commit 7f13f60
Showing
7 changed files
with
281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@dandori/cli": patch | ||
--- | ||
|
||
add notion cli |
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,174 @@ | ||
import { | ||
describe, | ||
beforeEach, | ||
afterEach, | ||
vi, | ||
expect, | ||
it, | ||
beforeAll, | ||
afterAll, | ||
Mock, | ||
} from "vitest"; | ||
import { DandoriTask } from "@dandori/core"; | ||
import { generateDandoriNotionPages } from "@dandori/ui"; | ||
import DandoriMiroCli from "../index"; | ||
import { rm, writeFile } from "fs/promises"; | ||
|
||
const tasks: DandoriTask[] = [ | ||
{ | ||
id: "1", | ||
name: "task1", | ||
deadline: "2021-01-01", | ||
description: "task1-description", | ||
fromTaskIdList: [], | ||
status: "todo", | ||
}, | ||
]; | ||
|
||
vi.mock("@dandori/core", () => ({ | ||
default: vi.fn(() => tasks), | ||
})); | ||
|
||
vi.mock("@dandori/ui", () => ({ | ||
generateDandoriNotionPages: vi.fn(), | ||
})); | ||
|
||
const mockGenerateDandoriNotionPages = generateDandoriNotionPages as Mock; | ||
|
||
describe("DandoriNotionCli", () => { | ||
const inputFileName = "DandoriNotionCli.txt"; | ||
const inputFileText = "DandoriNotionCli"; | ||
const loadProcessArgv = (options: string[]) => { | ||
process.argv = ["node", "cli.js", inputFileName, ...options]; | ||
}; | ||
|
||
beforeAll(async () => { | ||
await writeFile(inputFileName, inputFileText); | ||
}); | ||
|
||
afterAll(async () => { | ||
await rm(inputFileName); | ||
}); | ||
|
||
afterEach(() => { | ||
process.argv = []; | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe("with -d option", () => { | ||
const databaseId = "databaseId"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["-d", databaseId]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with database id", () => { | ||
expect(mockGenerateDandoriNotionPages.mock.lastCall[1]).toContain({ | ||
databaseId, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --name option", () => { | ||
const name = "Name"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--name", name]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.name", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
name, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --deadline option", () => { | ||
const deadline = "Deadline"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--deadline", deadline]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.deadline", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
deadline, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --status option", () => { | ||
const status = "Status"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--status", status]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.status", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
status, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --status-todo option", () => { | ||
const statusTodo = "ToDo"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--status-todo", statusTodo]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.status.todo", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
"status.todo": statusTodo, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --status-doing option", () => { | ||
const statusDoing = "Doing"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--status-doing", statusDoing]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.status.doing", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
"status.doing": statusDoing, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("with --status-done option", () => { | ||
const statusDone = "Done"; | ||
|
||
beforeEach(async () => { | ||
loadProcessArgv(["--status-done", statusDone]); | ||
await new DandoriMiroCli().run(); | ||
}); | ||
|
||
it("call generateDandoriNotionPages with databasePropertiesMap.status.done", () => { | ||
expect( | ||
mockGenerateDandoriNotionPages.mock.lastCall[1].databasePropertiesMap, | ||
).toContain({ | ||
"status.done": statusDone, | ||
}); | ||
}); | ||
}); | ||
}); |
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,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import DandoriNotionCli from "./index"; | ||
|
||
const cli = new DandoriNotionCli(); | ||
await cli.run(); |
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,39 @@ | ||
import { generateDandoriNotionPages } from "@dandori/ui"; | ||
import DandoriCoreCli from "../core"; | ||
|
||
export default class DandoriNotionCli extends DandoriCoreCli { | ||
override async run(): Promise<void> { | ||
const tasks = await this.generateDandoriTasks(); | ||
const opts = this.program.opts(); | ||
await generateDandoriNotionPages(tasks, { | ||
databaseId: opts.databaseId, | ||
databasePropertiesMap: { | ||
name: opts.name, | ||
deadline: opts.deadline, | ||
description: opts.description, | ||
status: opts.status, | ||
"status.todo": opts.statusTodo, | ||
"status.doing": opts.statusDoing, | ||
"status.done": opts.statusDone, | ||
}, | ||
}); | ||
} | ||
|
||
protected override buildCommand() { | ||
return super | ||
.buildCommand() | ||
.option("-d, --database-id <database-id>", "notion database id") | ||
.option("--name <name>", "notion page name property") | ||
.option("--deadline <deadline>", "notion page deadline property") | ||
.option("--status <status>", "notion page status property") | ||
.option("--status-todo <status-todo>", "notion page status todo property") | ||
.option( | ||
"--status-doing <status-doing>", | ||
"notion page status doing property", | ||
) | ||
.option( | ||
"--status-done <status-done>", | ||
"notion page status done property", | ||
); | ||
} | ||
} |