Skip to content

Commit cfb7816

Browse files
committed
feat(test): add comprehensive test suite for API modules
1 parent 7a85880 commit cfb7816

File tree

8 files changed

+24
-175
lines changed

8 files changed

+24
-175
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"version": "3.8.0",
44
"description": "A NodeJS wrapper for Square Cloud API",
55
"type": "module",
6-
"main": "./lib/index.cjs",
7-
"module": "./lib/index.mjs",
8-
"types": "./lib/index.d.mts",
6+
"main": "./lib/src.cjs",
7+
"module": "./lib/src.mjs",
8+
"types": "./lib/src.d.mts",
99
"exports": {
1010
".": {
1111
"import": {
12-
"types": "./lib/index.d.mts",
13-
"default": "./lib/index.mjs"
12+
"types": "./lib/src.d.mts",
13+
"default": "./lib/src.mjs"
1414
},
1515
"require": {
16-
"types": "./lib/index.d.cts",
17-
"default": "./lib/index.cjs"
16+
"types": "./lib/src.d.cts",
17+
"default": "./lib/src.cjs"
1818
}
1919
}
2020
},
@@ -28,7 +28,7 @@
2828
"check-types": "tsc --noEmit",
2929
"lint": "biome check --write .",
3030
"lint:ci": "biome check .",
31-
"test": "node --test test/*.test.js"
31+
"test": "node --experimental-strip-types --test test/*.test.ts"
3232
},
3333
"engines": {
3434
"node": ">=18.0.0"

test/api.test.js

Lines changed: 0 additions & 139 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
3+
import { setTimeout } from "node:timers/promises";
34
import { readFile } from "fs/promises";
45
import path from "path";
56
import { fileURLToPath } from "url";
67

7-
import { SquareCloudAPI } from "../lib/index.mjs";
8+
import { SquareCloudAPI } from "../lib/src.mjs";
89

910
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1011

1112
describe("ApplicationsModule", async () => {
12-
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
13+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY as string);
1314

1415
await it("should list all applications", async () => {
1516
const applications = await client.applications.get();
@@ -40,6 +41,7 @@ describe("ApplicationsModule", async () => {
4041
});
4142

4243
await it("should get application logs", async () => {
44+
await setTimeout(5000);
4345
const logs = await app.getLogs();
4446
assert.ok(typeof logs === "string");
4547
});
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import assert from "node:assert/strict";
22
import { before, describe, it } from "node:test";
33

4-
import { SquareCloudAPI } from "../lib/index.mjs";
4+
import { type Application, SquareCloudAPI } from "../lib/src.mjs";
55

66
describe("FilesModule", async () => {
7-
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY as string);
88

9-
/** @type {import("../lib").Application} */
10-
let testApp;
9+
let testApp: Application;
1110

1211
before(async () => {
1312
const apps = await client.applications.get();
14-
testApp = apps.first();
13+
testApp = apps.first() as Application;
1514

1615
if (!testApp) {
1716
throw new Error("No test application found");
@@ -72,11 +71,6 @@ describe("FilesModule", async () => {
7271
assert.ok(files.some((file) => file.name === "test2.txt"));
7372
});
7473

75-
await it("should handle non-existent file read", async () => {
76-
const content = await testApp.files.read("/non-existent.txt");
77-
assert.ok(content.byteLength === 0);
78-
});
79-
8074
await it("should delete file", async () => {
8175
const deleteResult = await testApp.files.delete("/test2.txt");
8276
assert.strictEqual(deleteResult, true);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import assert from "node:assert/strict";
22
import { before, describe, it } from "node:test";
33

4-
import { SquareCloudAPI } from "../lib/index.mjs";
4+
import { type Application, SquareCloudAPI } from "../lib/src.mjs";
55

66
describe("SnapshotsModule", async () => {
7-
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY as string);
88

9-
/** @type {import("../lib/index.js").Application} */
10-
let testApp;
9+
let testApp: Application;
1110

1211
before(async () => {
1312
const apps = await client.applications.get();
14-
testApp = apps.first();
13+
testApp = apps.first() as Application;
1514

1615
if (!testApp) {
1716
throw new Error("No test application found");
@@ -24,7 +23,7 @@ describe("SnapshotsModule", async () => {
2423
assert.ok(snapshot.url);
2524
assert.ok(snapshot.key);
2625
} catch (err) {
27-
if (err.message.includes("Rate Limit Exceeded")) {
26+
if (err instanceof Error && err.message.includes("Rate Limit Exceeded")) {
2827
t.skip("Rate limit exceeded");
2928
}
3029
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33

4-
import { SquareCloudAPI } from "../lib/index.mjs";
4+
import { SquareCloudAPI } from "../lib/src.mjs";
55

66
describe("UserModule", async () => {
7-
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY);
7+
const client = new SquareCloudAPI(process.env.SQUARE_API_KEY as string);
88

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

tsconfig.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ESNext",
4-
"lib": ["DOM", "ESNext"],
54
"module": "commonjs",
6-
"rootDir": "./src",
7-
"declaration": true,
8-
"sourceMap": true,
9-
"outDir": "./lib",
105
"esModuleInterop": true,
116
"forceConsistentCasingInFileNames": true,
127
"noImplicitAny": true,

tsdown.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { UserConfig } from "tsdown";
22

33
export default {
4-
target: "es2020",
54
format: ["cjs", "esm"],
65
outDir: "lib",
7-
dts: true,
86
minify: false,
9-
clean: true,
107
sourcemap: false,
8+
nodeProtocol: "strip",
119
} satisfies UserConfig;

0 commit comments

Comments
 (0)