Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 2859333

Browse files
authored
Merge pull request #56 from dubisdev/v3
v3
2 parents 4fede11 + 97a8aa5 commit 2859333

26 files changed

+545
-672
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Run Tests
22

3-
on: [pull_request, push]
3+
on: [pull_request]
44

55
jobs:
66
run_tests:

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "todoist-rest-client",
3-
"version": "2.5.0",
3+
"version": "3.0.0",
44
"description": "A simple todoist-rest-api client",
55
"author": "dubisdev",
66
"license": "MIT",
@@ -20,12 +20,13 @@
2020
"types": "dist/index.d.ts",
2121
"dependencies": {
2222
"axios": "^0.24.0",
23-
"moment": "^2.29.1"
23+
"uuid": "^8.3.2"
2424
},
2525
"devDependencies": {
2626
"@types/jest": "^27.0.2",
27+
"@types/uuid": "^8.3.1",
2728
"dotenv": "^10.0.0",
28-
"jest": "^27.3.0",
29+
"jest": "^27.3.1",
2930
"ts-jest": "^27.0.7",
3031
"typescript": "^4.4.4"
3132
},

src/TDSClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { task, project, section, label, comment } from "./submodules";
1+
import { task, project, section, label, comment, extras } from "./submodules";
22
import { ClientConstructor, TDSClient } from "./definitions";
33

44
const TDSClientConstructor: ClientConstructor = (apiToken): TDSClient => {
@@ -13,6 +13,7 @@ const TDSClientConstructor: ClientConstructor = (apiToken): TDSClient => {
1313
section: section(headers),
1414
label: label(headers),
1515
comment: comment(headers),
16+
extras: extras(headers),
1617
};
1718
};
1819

src/__tests__/comments.tests.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const myClient = TDSClient(process.env.TODOIST_TOKEN);
77
let inboxProjectID: number;
88
beforeAll(async () => {
99
inboxProjectID =
10-
(await myClient.project.getAllJSON()).find(
11-
(project) => project.inbox_project
12-
)?.id || 0;
10+
(await myClient.project.getAll()).find((project) => project.inbox_project)
11+
?.id || 0;
1312
});
1413

1514
describe("Client-Side Comment Creation", () => {
@@ -65,7 +64,7 @@ describe("API Comment Functions", () => {
6564
});
6665

6766
test("Get All Comments", async () => {
68-
const responseComments = await myClient.comment.getAllJSON({
67+
const responseComments = await myClient.comment.getAll({
6968
project_id: inboxProjectID,
7069
});
7170
const testCommmentExists = responseComments.some(
@@ -85,7 +84,7 @@ describe("API Comment Functions", () => {
8584
});
8685

8786
test("Delete All Previous Comments", async () => {
88-
let allCommentsJSON = await myClient.comment.getAllJSON({
87+
let allCommentsJSON = await myClient.comment.getAll({
8988
project_id: inboxProjectID,
9089
});
9190

src/__tests__/labels.tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("API Label Functions", () => {
4444
});
4545

4646
test("Get All Labels", async () => {
47-
const responseLabels = await myClient.label.getAllJSON();
47+
const responseLabels = await myClient.label.getAll();
4848
const testLabelExists = responseLabels.some(
4949
(labelObj) => labelObj.name === "Test_Label"
5050
);
@@ -54,7 +54,7 @@ describe("API Label Functions", () => {
5454
});
5555

5656
test("Get All Label Names", async () => {
57-
const responseLabels = await myClient.label.getAll();
57+
const responseLabels = await myClient.extras.getAllLabelNames();
5858
const testLabelExists = responseLabels.some(
5959
(name) => name === "Test_Label"
6060
);
@@ -72,7 +72,7 @@ describe("API Label Functions", () => {
7272
});
7373

7474
test("Delete All Previous Labels", async () => {
75-
let allLabelsJSON = await myClient.label.getAllJSON();
75+
let allLabelsJSON = await myClient.label.getAll();
7676

7777
let responses = await Promise.all(
7878
allLabelsJSON.map(async (label) => myClient.label.delete(label.id))

src/__tests__/projects.tests.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("API Project Functions", () => {
5252

5353
// 4 active projects now
5454
test("Get All Active Projects JSON", async () => {
55-
const responseProjects = await myClient.project.getAllJSON();
55+
const responseProjects = await myClient.project.getAll();
5656

5757
const projectExists = responseProjects.some(
5858
(projectObj) => projectObj.name === "P2"
@@ -62,12 +62,9 @@ describe("API Project Functions", () => {
6262
expect(projectExists).toBe(true);
6363
});
6464

65-
test("Get All Active Project Names", async () => {
66-
const responseProjects = await myClient.project.getAll();
67-
const projectExists = responseProjects.some((name) => name === "P2");
68-
69-
expect(responseProjects.length).toBe(4);
70-
expect(projectExists).toBe(true);
65+
test("Test getAllProjectNames", async () => {
66+
let names = await myClient.extras.getAllProjectNames();
67+
expect(typeof names[0]).toEqual("string");
7168
});
7269

7370
test("Update a project", async () => {
@@ -87,7 +84,7 @@ describe("API Project Functions", () => {
8784
});
8885

8986
test("Delete All Previous Projects", async () => {
90-
let allProjectsJSON = await myClient.project.getAllJSON();
87+
let allProjectsJSON = await myClient.project.getAll();
9188

9289
let responses = await Promise.all(
9390
allProjectsJSON.map(async (project) => {

src/__tests__/section.tests.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const myClient = TDSClient(process.env.TODOIST_TOKEN);
77
let inboxProjectID: number;
88
beforeAll(async () => {
99
inboxProjectID =
10-
(await myClient.project.getAllJSON()).find(
11-
(project) => project.inbox_project
12-
)?.id || 0;
10+
(await myClient.project.getAll()).find((project) => project.inbox_project)
11+
?.id || 0;
1312
});
1413

1514
describe("Client-Side Section Creation", () => {
@@ -69,7 +68,7 @@ describe("API Section Functions", () => {
6968
});
7069

7170
test("Get All Sections", async () => {
72-
const responseSections = await myClient.section.getAllJSON(inboxProjectID);
71+
const responseSections = await myClient.section.getAll(inboxProjectID);
7372
const sectionExists = responseSections.some(
7473
(sectionObj) => sectionObj.name === "Section 2"
7574
);
@@ -79,7 +78,9 @@ describe("API Section Functions", () => {
7978
});
8079

8180
test("Get All Section Names", async () => {
82-
const responseSections = await myClient.section.getAll();
81+
const responseSections = await myClient.extras.getAllSectionNames(
82+
inboxProjectID
83+
);
8384
const sectionExists = responseSections.some((name) => name === "Section 2");
8485

8586
expect(responseSections.length).toBe(3);
@@ -89,12 +90,10 @@ describe("API Section Functions", () => {
8990
test("Get Sections from Project (Inbox)", async () => {
9091
const responseSections = await myClient.section.getAll(inboxProjectID);
9192
const testSectionExists = responseSections.some(
92-
(name) => name === "Test Section"
93+
({ name }) => name === "Test Section"
9394
);
9495

9596
expect(responseSections.length).toBe(3);
96-
expect(typeof responseSections[0]).toBe("string");
97-
9897
expect(testSectionExists).toBe(true);
9998
});
10099

@@ -107,7 +106,7 @@ describe("API Section Functions", () => {
107106
});
108107

109108
test("Delete All Previous Sections", async () => {
110-
let allSectionsJSON = await myClient.section.getAllJSON();
109+
let allSectionsJSON = await myClient.section.getAll();
111110

112111
let responses = await Promise.all(
113112
allSectionsJSON.map(async (section) =>

src/__tests__/task.tests.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import TDSClient, { Task } from "..";
22
import { APITaskObject, CreatableTask } from "../definitions";
3-
import moment from "moment";
43

54
const myClient = TDSClient(process.env.TODOIST_TOKEN);
65

76
beforeAll(async () => {
8-
let allTasksJSON = await myClient.task.getAllJSON();
7+
let allTasksJSON = await myClient.task.getAll();
98
await Promise.all(allTasksJSON.map((task) => myClient.task.delete(task.id)));
109
console.log("Init: Deleted all tasks!");
1110
});
@@ -58,7 +57,7 @@ describe("API Tasks Functions", () => {
5857
});
5958

6059
test("Close A Task", async () => {
61-
let status = (await myClient.task.closeTask(generalExpectedTaskID)).status;
60+
let status = (await myClient.task.close(generalExpectedTaskID)).status;
6261

6362
expect(status).toBe(204);
6463
});
@@ -85,7 +84,7 @@ describe("API Tasks Functions", () => {
8584
});
8685

8786
test("Get All Active Tasks JSON", async () => {
88-
const responseTasks = await myClient.task.getAllJSON();
87+
const responseTasks = await myClient.task.getAll();
8988

9089
const taskExists = responseTasks.some(
9190
(taskObj) => taskObj.content === "Second task"
@@ -95,16 +94,8 @@ describe("API Tasks Functions", () => {
9594
expect(taskExists).toBe(true);
9695
});
9796

98-
test("Get All Active Tasks Names", async () => {
99-
const responseTasks = await myClient.task.getAll();
100-
const taskExists = responseTasks.some((name) => name === "Second task");
101-
102-
expect(responseTasks.length).toBe(2);
103-
expect(taskExists).toBe(true);
104-
});
105-
10697
test("Delete All Previous Tasks", async () => {
107-
let allTasksJSON = await myClient.task.getAllJSON();
98+
let allTasksJSON = await myClient.task.getAll();
10899
let responses = await Promise.all(
109100
allTasksJSON.map((task) => myClient.task.delete(task.id))
110101
);
@@ -130,27 +121,22 @@ describe("API Tasks Functions", () => {
130121
let allTodayJSON, allTodayNames;
131122

132123
await Promise.all([
133-
(allTodayJSON = await myClient.task.getTodayJSON()),
134-
(allTodayNames = await myClient.task.getToday()),
124+
(allTodayJSON = await myClient.extras.getTodayTaskJSON()),
125+
(allTodayNames = await myClient.extras.getTodayTaskNames()),
135126
]);
136-
137127
const firstTaskExists =
138128
allTodayJSON.some((taskObj) => taskObj.content === "First task") &&
139129
allTodayNames.some((name) => name === "First task");
140130

141-
let normalDate = new Date().toISOString().substring(0, 10);
142-
let momentDate = moment.parseZone(new Date()).format().substring(0, 10);
143-
144-
if (normalDate === momentDate) {
145-
// GMT day = local day
146-
expect(allTodayJSON.length).toBe(2);
147-
expect(typeof allTodayJSON[0]).toBe("object");
148-
expect(firstTaskExists).toBe(true);
149-
} else {
150-
// GMT day != local day (offset influence in day)
151-
expect(allTodayJSON.length).toBe(0);
152-
expect(firstTaskExists).toBe(false);
153-
}
131+
expect(allTodayJSON.length).toBe(2);
132+
expect(typeof allTodayJSON[0]).toBe("object");
133+
expect(firstTaskExists).toBe(true);
134+
});
135+
136+
test("Test getAllTaskNames", async () => {
137+
let names = await myClient.extras.getAllTaskNames();
138+
139+
expect(typeof names[0]).toEqual("string");
154140
});
155141

156142
test("Search Tasks", async () => {
@@ -171,7 +157,7 @@ describe("API Tasks Functions", () => {
171157
});
172158

173159
afterAll(async () => {
174-
let allTasksJSON = await myClient.task.getAllJSON();
160+
let allTasksJSON = await myClient.task.getAll();
175161
await Promise.all(allTasksJSON.map((task) => myClient.task.delete(task.id)));
176162
console.log("Finish: Deleted all tasks!");
177163
});

src/definitions/Client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
SectionModule,
55
LabelModule,
66
CommentModule,
7+
ExtrasModule,
78
} from ".";
89
import { AxiosRequestHeaders } from "axios";
910

@@ -18,6 +19,7 @@ export interface TDSClient {
1819
section: SectionModule;
1920
label: LabelModule;
2021
comment: CommentModule;
22+
extras: ExtrasModule;
2123
}
2224

2325
export interface ClientConstructor {

src/definitions/Comments.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { AxiosResponse } from "axios";
22

33
export interface CommentModule {
44
get: (id: string | number) => Promise<APICommentObject>;
5-
65
create: (comment: CreatableComment) => Promise<APICommentObject>;
76
delete: (id: number | string) => Promise<AxiosResponse>;
8-
getAllJSON: (params: CommentSearchableParams) => Promise<APICommentObject[]>;
9-
7+
getAll: (params: CommentSearchableParams) => Promise<APICommentObject[]>;
108
update: (
119
id: number | string,
1210
comment: CommentUpdatableParameters
@@ -23,14 +21,14 @@ export type UserCreatedProjectComment = {
2321
task_id?: undefined;
2422
project_id: number;
2523
content?: string;
26-
attachment?: object;
24+
attachment?: TodoistFile;
2725
};
2826

2927
export type UserCreatedTaskComment = {
3028
task_id: number;
3129
project_id?: undefined;
3230
content?: string;
33-
attachment?: object;
31+
attachment?: TodoistFile;
3432
};
3533

3634
export type CreatableComment = UserCreatedComment & {
@@ -41,28 +39,21 @@ export type CreatableComment = UserCreatedComment & {
4139

4240
export type APICommentObject = APIProjectCommentObject | APITaskCommentObject;
4341

44-
const myComment: APICommentObject = {
45-
id: 123456,
46-
posted: "",
47-
content: "",
48-
project_id: 123456,
49-
};
50-
5142
export type APIProjectCommentObject = {
5243
id: number;
5344
project_id: number;
5445
task_id?: undefined;
5546
posted: string;
5647
content: string;
57-
attachment?: object;
48+
attachment?: TodoistFile;
5849
};
5950
export type APITaskCommentObject = {
6051
id: number;
6152
task_id: number;
6253
project_id?: undefined;
6354
posted: string;
6455
content: string;
65-
attachment?: object;
56+
attachment?: TodoistFile;
6657
};
6758

6859
// See https://developer.todoist.com/rest/v1/#update-a-comment
@@ -73,3 +64,28 @@ export interface CommentUpdatableParameters {
7364
export type CommentSearchableParams =
7465
| { project_id: number; task_id?: undefined }
7566
| { task_id: number; project_id?: undefined };
67+
68+
export interface BaseFileProperties {
69+
file_name: string;
70+
file_size: number;
71+
file_type: string;
72+
file_url: string;
73+
upload_state?: "pending" | "completed";
74+
}
75+
76+
export interface ImageFileProperties {
77+
tn_l: [string, number, number];
78+
tn_m: [string, number, number];
79+
tn_s: [string, number, number];
80+
file_duration?: undefined;
81+
}
82+
83+
export interface AudioFileProperties {
84+
file_duration: number;
85+
tn_l?: undefined;
86+
tn_m?: undefined;
87+
tn_s?: undefined;
88+
}
89+
90+
export type TodoistFile = BaseFileProperties &
91+
(ImageFileProperties | AudioFileProperties);

0 commit comments

Comments
 (0)