Skip to content

Commit 60b7026

Browse files
committed
refactor(tests): migrate to describe/it pattern
1 parent dc5e776 commit 60b7026

File tree

6 files changed

+55
-63
lines changed

6 files changed

+55
-63
lines changed

src/modules/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { readFile } from "fs/promises";
21
import { join } from "path";
2+
import { readFile } from "fs/promises";
33

44
import { assertPathLike, assertString } from "@/assertions/literal";
55
import { Routes } from "@/lib/routes";

test/api.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import assert from "node:assert/strict";
2-
import test from "node:test";
2+
import { describe, it } from "node:test";
33
import { APIService } from "../lib/services/api.js";
44

5-
test("APIService", async (t) => {
5+
describe("APIService", async () => {
66
const service = new APIService("123-test-key");
77

8-
await t.test("should initialize with correct properties", () => {
8+
await it("should initialize with correct properties", () => {
99
assert.strictEqual(service.baseUrl, "https://api.squarecloud.app");
1010
assert.strictEqual(service.version, "v2");
1111
assert.strictEqual(service.userId, "123");
1212
});
1313

14-
await t.test("should parse request options correctly", async (t) => {
14+
await it("should parse request options correctly", async (t) => {
1515
const originalFetch = global.fetch;
1616

17-
await t.test("should handle basic GET request", async () => {
17+
await it("should handle basic GET request", async () => {
1818
let requestUrl;
1919
let requestInit;
2020

@@ -35,7 +35,7 @@ test("APIService", async (t) => {
3535
assert.strictEqual(requestInit.headers.Accept, "application/json");
3636
});
3737

38-
await t.test("should handle query parameters", async () => {
38+
await it("should handle query parameters", async () => {
3939
let requestUrl;
4040

4141
global.fetch = async (url, init) => {
@@ -51,7 +51,7 @@ test("APIService", async (t) => {
5151
assert.ok(requestUrl.toString().includes("param2=value2"));
5252
});
5353

54-
await t.test("should handle JSON body", async () => {
54+
await it("should handle JSON body", async () => {
5555
let requestInit;
5656

5757
global.fetch = async (url, init) => {
@@ -72,7 +72,7 @@ test("APIService", async (t) => {
7272
assert.strictEqual(requestInit.body, JSON.stringify(body));
7373
});
7474

75-
await t.test("should handle FormData body", async () => {
75+
await it("should handle FormData body", async () => {
7676
let requestInit;
7777

7878
global.fetch = async (url, init) => {
@@ -90,7 +90,7 @@ test("APIService", async (t) => {
9090
assert.ok(!requestInit.headers["Content-Type"]);
9191
});
9292

93-
await t.test("should handle error responses", async () => {
93+
await it("should handle error responses", async () => {
9494
global.fetch = async () => {
9595
return new Response(
9696
JSON.stringify({ status: "error", code: "TEST_ERROR" }),
@@ -103,7 +103,7 @@ test("APIService", async (t) => {
103103
});
104104
});
105105

106-
await t.test("should handle network errors", async () => {
106+
await it("should handle network errors", async () => {
107107
global.fetch = async () => {
108108
throw new Error("Network error");
109109
};
@@ -113,7 +113,7 @@ test("APIService", async (t) => {
113113
});
114114
});
115115

116-
await t.test("should handle specific HTTP status codes", async () => {
116+
await it("should handle specific HTTP status codes", async () => {
117117
const statusTests = [
118118
{ status: 413, code: "Payload Too Large" },
119119
{ status: 429, code: "Rate Limit Exceeded" },

test/applications.test.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,77 @@
11
import assert from "node:assert/strict";
2-
import test from "node:test";
3-
import { setTimeout } from "node:timers/promises";
2+
import { describe, it } from "node:test";
43
import path from "path";
54
import { fileURLToPath } from "url";
65
import { readFile } from "fs/promises";
76
import { SquareCloudAPI } from "../lib/index.js";
87

98
const __dirname = path.dirname(fileURLToPath(import.meta.url));
109

11-
test("ApplicationsModule", async (t) => {
10+
describe("ApplicationsModule", async () => {
1211
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
1312

14-
await t.test("should list all applications", async () => {
13+
await it("should list all applications", async () => {
1514
const applications = await client.applications.get();
1615
assert.ok(applications);
1716
assert.ok(applications.size >= 0);
1817
});
1918

20-
await t.test("should handle application lifecycle", async (t) => {
19+
await describe("Lifecycle", async (t) => {
2120
const testAppPath = path.join(__dirname, "fixtures/test-app.zip");
2221
const fileContent = await readFile(testAppPath);
2322

2423
const createdApp = await client.applications.create(fileContent);
2524

26-
await t.test("should create application", async () => {
25+
await it("should create application", async () => {
2726
assert.ok(createdApp);
2827
assert.ok(createdApp.id);
2928
});
3029

3130
const app = await client.applications.fetch(createdApp.id);
3231

33-
await t.test("should fetch application", async () => {
32+
await it("should fetch application", async () => {
3433
assert.strictEqual(app.id, createdApp.id);
3534
});
3635

37-
await t.test("should get status", async () => {
36+
await it("should get status", async () => {
3837
const status = await app.getStatus();
3938
assert.strictEqual(status.applicationId, createdApp.id);
4039
});
4140

42-
await t.test("should get application logs", async () => {
41+
await it("should get application logs", async () => {
4342
const logs = await app.getLogs();
4443
assert.ok(typeof logs === "string");
4544
});
4645

4746
const testFilePath = path.join(__dirname, "fixtures/test-file.txt");
4847

49-
await t.test("should commit files as buffer to application", async () => {
50-
const fileContent = await readFile(testFilePath);
51-
52-
const bufferResult = await app.commit(fileContent, "test-file.txt");
53-
assert.strictEqual(bufferResult, true);
54-
});
55-
56-
await setTimeout(10000);
57-
58-
await t.test("should commit files as path to application", async () => {
59-
const pathResult = await app.commit(testFilePath, "test-file2.txt");
48+
await it("should commit file to application", async () => {
49+
const pathResult = await app.commit(testFilePath, "test-file.txt");
6050
assert.strictEqual(pathResult, true);
6151
});
6252

63-
await t.test("should start application", async () => {
64-
const result = await app.start();
53+
await it("should stop application", async () => {
54+
const result = await app.stop();
6555
assert.strictEqual(result, true);
6656
});
6757

68-
await t.test("should restart application", async () => {
69-
const result = await app.restart();
58+
await it("should start application", async () => {
59+
const result = await app.start();
7060
assert.strictEqual(result, true);
7161
});
7262

73-
await t.test("should stop application", async () => {
74-
const result = await app.stop();
63+
await it("should restart application", async () => {
64+
const result = await app.restart();
7565
assert.strictEqual(result, true);
7666
});
7767

78-
await t.test("should delete application", async () => {
68+
await it("should delete application", async () => {
7969
const deleteResult = await app.delete();
8070
assert.strictEqual(deleteResult, true);
8171
});
8272
});
8373

84-
await t.test("should get status for all applications", async () => {
74+
await it("should get status for all applications", async () => {
8575
const statuses = await client.applications.statusAll();
8676
assert.ok(Array.isArray(statuses));
8777
});

test/backups.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import assert from "node:assert/strict";
2-
import test from "node:test";
2+
import { before, describe, it } from "node:test";
33
import { SquareCloudAPI } from "../lib/index.js";
44

5-
test("BackupsModule", async (t) => {
5+
describe("BackupsModule", async () => {
66
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
78
/** @type import("../lib").Application */
89
let testApp;
910

10-
t.before(async () => {
11+
before(async () => {
1112
const apps = await client.applications.get();
1213
testApp = apps.first();
1314

@@ -16,7 +17,7 @@ test("BackupsModule", async (t) => {
1617
}
1718
});
1819

19-
await t.test("should create backup", async (t) => {
20+
await it("should create backup", async (t) => {
2021
try {
2122
const backup = await testApp.backups.create();
2223
assert.ok(backup.url);
@@ -28,14 +29,14 @@ test("BackupsModule", async (t) => {
2829
}
2930
});
3031

31-
await t.test("should download backup", async () => {
32+
await it("should download backup", async () => {
3233
const backups = await testApp.backups.list();
3334
const buffer = await backups[0].download();
3435
assert.ok(Buffer.isBuffer(buffer));
3536
assert.ok(buffer.length > 0);
3637
});
3738

38-
await t.test("should list backups", async () => {
39+
await it("should list backups", async () => {
3940
const backups = await testApp.backups.list();
4041

4142
assert.ok(Array.isArray(backups));
@@ -46,14 +47,14 @@ test("BackupsModule", async (t) => {
4647
}
4748
});
4849

49-
await t.test("should update cache on backups list", async () => {
50+
await it("should update cache on backups list", async () => {
5051
const backups = await testApp.backups.list();
5152
const cachedBackups = testApp.cache.get("backups");
5253

5354
assert.deepStrictEqual(cachedBackups, backups);
5455
});
5556

56-
await t.test("should emit backupsUpdate event", async () => {
57+
await it("should emit backupsUpdate event", async () => {
5758
let emitted = false;
5859
const oldBackups = testApp.cache.get("backups");
5960

test/files.test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import assert from "node:assert/strict";
2-
import test from "node:test";
2+
import { before, describe, it } from "node:test";
33
import { SquareCloudAPI } from "../lib/index.js";
44

5-
test("FilesModule", async (t) => {
5+
describe("FilesModule", async () => {
66
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
78
/** @type {import("../lib").Application} */
89
let testApp;
910

10-
t.before(async () => {
11+
before(async () => {
1112
const apps = await client.applications.get();
1213
testApp = apps.first();
1314

@@ -16,7 +17,7 @@ test("FilesModule", async (t) => {
1617
}
1718
});
1819

19-
await t.test("should list files in root directory", async () => {
20+
await it("should list files in root directory", async () => {
2021
const files = await testApp.files.list();
2122
assert.ok(Array.isArray(files));
2223
if (files.length > 0) {
@@ -30,7 +31,7 @@ test("FilesModule", async (t) => {
3031
}
3132
});
3233

33-
await t.test("should create and read file", async () => {
34+
await it("should create and read file", async () => {
3435
const testContent = "test content";
3536
const fileName = "test.txt";
3637

@@ -45,7 +46,7 @@ test("FilesModule", async (t) => {
4546
assert.strictEqual(fileContent?.toString(), testContent);
4647
});
4748

48-
await t.test("should edit existing file", async () => {
49+
await it("should edit existing file", async () => {
4950
const newContent = "updated content";
5051
const fileName = "test.txt";
5152

@@ -59,7 +60,7 @@ test("FilesModule", async (t) => {
5960
assert.strictEqual(fileContent?.toString(), newContent);
6061
});
6162

62-
await t.test("should move/rename file", async () => {
63+
await it("should move/rename file", async () => {
6364
const oldPath = "/test.txt";
6465
const newPath = "/test2.txt";
6566

@@ -70,20 +71,20 @@ test("FilesModule", async (t) => {
7071
assert.ok(files.some((file) => file.name === "test2.txt"));
7172
});
7273

73-
await t.test("should handle non-existent file read", async () => {
74+
await it("should handle non-existent file read", async () => {
7475
const content = await testApp.files.read("/non-existent.txt");
7576
assert.ok(content.byteLength === 0);
7677
});
7778

78-
await t.test("should delete file", async () => {
79+
await it("should delete file", async () => {
7980
const deleteResult = await testApp.files.delete("/test2.txt");
8081
assert.strictEqual(deleteResult, true);
8182

8283
const files = await testApp.files.list();
8384
assert.ok(!files.some((file) => file.name === "test2.txt"));
8485
});
8586

86-
await t.test("should handle directory operations", async () => {
87+
await it("should handle directory operations", async () => {
8788
await testApp.files.create(Buffer.from("file1"), "file1.txt", "/testdir");
8889
await testApp.files.create(Buffer.from("file2"), "file2.txt", "/testdir");
8990

test/user.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import assert from "node:assert/strict";
2-
import test from "node:test";
2+
import { describe, it } from "node:test";
33
import { SquareCloudAPI } from "../lib/index.js";
44

5-
test("UserModule", async (t) => {
5+
describe("UserModule", async () => {
66
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
77

8-
await t.test("should get user information", async () => {
8+
await it("should get user information", async () => {
99
const user = await client.user.get();
1010

1111
assert.ok(user);
@@ -16,15 +16,15 @@ test("UserModule", async (t) => {
1616
assert.ok(user.applications.size >= 0);
1717
});
1818

19-
await t.test("should update cache on user fetch", async () => {
19+
await it("should update cache on user fetch", async () => {
2020
const firstUser = await client.user.get();
2121
const cachedUser = client.cache.get("user");
2222

2323
assert.strictEqual(cachedUser?.id, firstUser.id);
2424
assert.strictEqual(cachedUser?.email, firstUser.email);
2525
});
2626

27-
await t.test("should emit userUpdate event", async () => {
27+
await it("should emit userUpdate event", async () => {
2828
let emitted = false;
2929
const oldUser = client.cache.get("user");
3030

0 commit comments

Comments
 (0)