Skip to content

Commit 1896cf6

Browse files
committed
test: add tests for ApplicationsModule
1 parent 2803f49 commit 1896cf6

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

test/applications.test.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { readFile } from "fs/promises";
2+
import assert from "node:assert/strict";
3+
import test from "node:test";
4+
import { setTimeout } from "node:timers/promises";
5+
import path from "path";
6+
import { fileURLToPath } from "url";
7+
import { SquareCloudAPI } from "../lib/index.js";
8+
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
11+
test("ApplicationsModule", async (t) => {
12+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
13+
14+
await t.test("should list all applications", async () => {
15+
const applications = await client.applications.get();
16+
assert.ok(applications);
17+
assert.ok(applications.size >= 0);
18+
});
19+
20+
await t.test("should handle application lifecycle", async (t) => {
21+
const testAppPath = path.join(__dirname, "fixtures/test-app.zip");
22+
const fileContent = await readFile(testAppPath);
23+
24+
const createdApp = await client.applications.create(fileContent);
25+
26+
await t.test("should create application", async () => {
27+
assert.ok(createdApp);
28+
assert.ok(createdApp.id);
29+
});
30+
31+
const app = await client.applications.fetch(createdApp.id);
32+
33+
await t.test("should fetch application", async () => {
34+
assert.strictEqual(app.id, createdApp.id);
35+
});
36+
37+
await t.test("should get status", async () => {
38+
const status = await app.getStatus();
39+
assert.strictEqual(status.applicationId, createdApp.id);
40+
});
41+
42+
await t.test("should get application logs", async () => {
43+
const logs = await app.getLogs();
44+
assert.ok(typeof logs === "string");
45+
});
46+
47+
await t.test("should commit files to application", async () => {
48+
const testFilePath = path.join(__dirname, "fixtures/test-file.txt");
49+
const fileContent = await readFile(testFilePath);
50+
51+
const bufferResult = await app.commit(fileContent, "test-file.txt");
52+
assert.strictEqual(bufferResult, true);
53+
54+
await setTimeout(10000);
55+
56+
const pathResult = await app.commit(testFilePath, "test-file2.txt");
57+
assert.strictEqual(pathResult, true);
58+
});
59+
60+
await t.test("should start application", async () => {
61+
const result = await app.start();
62+
assert.strictEqual(result, true);
63+
});
64+
65+
await t.test("should restart application", async () => {
66+
const result = await app.restart();
67+
assert.strictEqual(result, true);
68+
});
69+
70+
await t.test("should stop application", async () => {
71+
const result = await app.stop();
72+
assert.strictEqual(result, true);
73+
});
74+
75+
await t.test("should delete application", async () => {
76+
const deleteResult = await app.delete();
77+
assert.strictEqual(deleteResult, true);
78+
});
79+
});
80+
81+
await t.test("should get status for all applications", async () => {
82+
const statuses = await client.applications.statusAll();
83+
assert.ok(Array.isArray(statuses));
84+
});
85+
});

test/fixtures/test-app.zip

977 Bytes
Binary file not shown.

test/fixtures/test-file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World!

0 commit comments

Comments
 (0)