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