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

Commit fb4c6e8

Browse files
committed
CI: use native tests from node 18
1 parent cf75d20 commit fb4c6e8

20 files changed

+676
-3524
lines changed

.github/workflows/release_manager.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v1
1414
- uses: actions/setup-node@v1
1515
with:
16-
node-version: 12
16+
node-version: 18
1717
- name: Installing project dependencies
1818
run: yarn
1919
- name: Running tests
@@ -32,7 +32,7 @@ jobs:
3232
- uses: actions/checkout@v1
3333
- uses: actions/setup-node@v1
3434
with:
35-
node-version: 12
35+
node-version: 18
3636
- run: yarn install
3737
- run: yarn prepublish
3838

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v1
1111
- uses: actions/setup-node@v1
1212
with:
13-
node-version: 12
13+
node-version: 18
1414
- name: Installing project dependencies
1515
run: yarn
1616
- name: Running tests

jest.config.mjs

Lines changed: 0 additions & 20 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818
"uuid": "8.3.2"
1919
},
2020
"devDependencies": {
21-
"@types/jest": "27.4.1",
2221
"@types/uuid": "8.3.4",
2322
"@types/node": "17.0.25",
2423
"dotenv": "10.0.0",
25-
"jest": "27.5.1",
26-
"ts-jest": "27.1.4",
2724
"typescript": "4.6.3"
2825
},
2926
"scripts": {
3027
"prepublish": "tsc",
31-
"test": "jest"
28+
"test": "tsc && node ./src/__tests__/index.js"
3229
},
3330
"repository": {
3431
"type": "git",

src/__tests__/client.tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import TDSClient from "../../dist/index.js";
2+
import test from "node:test";
3+
import assert from "node:assert";
4+
5+
test("Module importing and Client initialization", async (t) => {
6+
await t.test("Correctly imported and exported", () => {
7+
assert.strictEqual(typeof TDSClient, "function");
8+
});
9+
10+
await t.test("Throw error when no token", () => {
11+
assert.throws(TDSClient);
12+
});
13+
14+
await t.test("Create client when token exists", () => {
15+
assert.doesNotThrow(() => TDSClient("token"));
16+
});
17+
});

src/__tests__/client.tests.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/__tests__/comments.tests.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import test from "node:test";
2+
import assert from "node:assert";
3+
4+
import TDSClient, { Comment } from "../../dist/index.js";
5+
6+
const myClient = TDSClient(process.env.TODOIST_TOKEN);
7+
8+
// get the inbox project id
9+
let inboxProjectID;
10+
11+
inboxProjectID =
12+
(await myClient.project.getAll()).find((project) => project.inbox_project)
13+
?.id || 0;
14+
15+
await test("Client-Side Comment Creation", async (t) => {
16+
await t.test("Create Empty Comment", () => {
17+
const emptyComment = Comment({ task_id: 123456 });
18+
assert.deepStrictEqual(emptyComment, {
19+
content: "_No_Content_Provided_",
20+
task_id: 123456,
21+
});
22+
});
23+
24+
await t.test("Create Normal Comment", () => {
25+
let myComment = Comment({ content: "Test Content", task_id: 123456 });
26+
assert.deepStrictEqual(myComment, {
27+
content: "Test Content",
28+
task_id: 123456,
29+
});
30+
});
31+
});
32+
33+
await test("API Comment Functions", async (t) => {
34+
let commentID;
35+
36+
await t.test("Create A Comment", async () => {
37+
let apiComment = await myClient.comment.create({
38+
content: "This is the content",
39+
project_id: inboxProjectID,
40+
});
41+
42+
assert(apiComment.id);
43+
44+
commentID = apiComment.id;
45+
});
46+
47+
await t.test("Get A Comment", async () => {
48+
let apiComment = await myClient.comment.get(commentID);
49+
50+
assert.deepStrictEqual(apiComment.content, "This is the content");
51+
});
52+
53+
await t.test("Create Two More Comments", async () => {
54+
return await Promise.all([
55+
await myClient.comment.create({
56+
content: "Comment 2",
57+
project_id: inboxProjectID,
58+
}),
59+
await myClient.comment.create({
60+
content: "Comment 3",
61+
project_id: inboxProjectID,
62+
}),
63+
]);
64+
});
65+
66+
await t.test("Get All Comments", async () => {
67+
const responseComments = await myClient.comment.getAll({
68+
project_id: inboxProjectID,
69+
});
70+
const testCommmentExists = responseComments.some(
71+
(commentObj) => commentObj.content === "This is the content"
72+
);
73+
74+
assert(testCommmentExists);
75+
assert(responseComments.length === 3);
76+
});
77+
78+
await t.test("Update a comment", async () => {
79+
const repsonse = await myClient.comment.update(commentID, {
80+
content: "New content",
81+
});
82+
83+
assert(repsonse.status === 204);
84+
});
85+
86+
await t.test("Delete All Previous Comments", async () => {
87+
let allCommentsJSON = await myClient.comment.getAll({
88+
project_id: inboxProjectID,
89+
});
90+
91+
let responses = await Promise.all(
92+
allCommentsJSON.map(async (comment) =>
93+
myClient.comment.delete(comment.id)
94+
)
95+
);
96+
97+
responses.forEach(({ status }) => assert(status === 204));
98+
});
99+
});

src/__tests__/comments.tests.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/__tests__/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import dotenv from "dotenv";
2+
dotenv.config();
3+
4+
await import("./client.tests.js");
5+
await import("./task.tests.js");
6+
await import("./projects.tests.js");
7+
await import("./labels.tests.js");
8+
await import("./comments.tests.js");

src/__tests__/labels.tests.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import test from "node:test";
2+
import assert from "node:assert";
3+
4+
import TDSClient, { Label } from "../../dist/index.js";
5+
6+
const myClient = TDSClient(process.env.TODOIST_TOKEN);
7+
8+
await test("Client-Side Label Creation", async (t) => {
9+
await t.test("Create Empty Label", () => {
10+
const emptyLabel = Label();
11+
assert.deepStrictEqual(emptyLabel, { name: "_No_Label_Name_Provided_" });
12+
});
13+
14+
await t.test("Create Normal Label", () => {
15+
let myLabel = Label({ name: "Label Name" });
16+
assert.deepStrictEqual(myLabel, { name: "Label Name" });
17+
});
18+
});
19+
20+
await test("API Label Functions", async (t) => {
21+
let labelID;
22+
23+
await t.test("Create A Label", async () => {
24+
let apiLabel = await myClient.label.create({ name: "Test Label" });
25+
26+
assert(apiLabel.id);
27+
28+
labelID = apiLabel.id;
29+
});
30+
31+
await t.test("Get A Label", async () => {
32+
let apiLabel = await myClient.label.get(labelID);
33+
34+
assert.deepStrictEqual(apiLabel.name, "Test_Label");
35+
});
36+
37+
// 2 active projects now
38+
await t.test("Create Two More Labels", async () => {
39+
return await Promise.all([
40+
myClient.label.create({ name: "Label 2" }),
41+
myClient.label.create({ name: "Label 3" }),
42+
]);
43+
});
44+
45+
await t.test("Get All Labels", async () => {
46+
const responseLabels = await myClient.label.getAll();
47+
const testLabelExists = responseLabels.some(
48+
(labelObj) => labelObj.name === "Test_Label"
49+
);
50+
51+
assert(testLabelExists);
52+
assert(responseLabels.length === 3);
53+
});
54+
55+
await t.test("Get All Label Names", async () => {
56+
const responseLabels = await myClient.extras.getAllLabelNames();
57+
const testLabelExists = responseLabels.some(
58+
(name) => name === "Test_Label"
59+
);
60+
61+
assert(testLabelExists);
62+
assert(responseLabels.length === 3);
63+
});
64+
65+
await t.test("Update a label", async () => {
66+
const response = await myClient.label.update(labelID, {
67+
name: "New label name",
68+
});
69+
70+
assert(response.status === 204);
71+
});
72+
73+
await t.test("Delete All Previous Labels", async () => {
74+
let allLabelsJSON = await myClient.label.getAll();
75+
76+
let responses = await Promise.all(
77+
allLabelsJSON.map(async (label) => myClient.label.delete(label.id))
78+
);
79+
80+
responses.forEach(({ status }) => assert(status === 204));
81+
});
82+
});

0 commit comments

Comments
 (0)