Skip to content

Commit c65e226

Browse files
committed
add testing files
1 parent a7b784d commit c65e226

File tree

7 files changed

+64
-3
lines changed

7 files changed

+64
-3
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# dependencies
55
/node_modules/
66

7-
# test
8-
/test/
7+
# env
8+
.env

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"build:lint": "biome check .",
1313
"build:ts": "tsup ./src",
1414
"lint": "biome check --apply .",
15-
"test": "tsnd ./test/index.ts",
15+
"test": "node --env-file=.env -r ts-node/register",
16+
"test:list": "npm run test ./test/list.test.ts",
17+
"test:create": "npm run test ./test/create.test.ts",
18+
"test:delete": "npm run test ./test/delete.test.ts",
19+
"test:mime": "npm run test ./test/mimetypes.test.ts",
1620
"prepare": "husky"
1721
},
1822
"engines": {

test/create.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { type CreateObjectType, MimeTypes } from "../src";
2+
import { blob } from "./index.test";
3+
4+
// Create object using absolute path
5+
6+
const createWithPathPayload: CreateObjectType = {
7+
file: "package.json",
8+
name: "testing",
9+
};
10+
11+
blob.objects.create(createWithPathPayload).then(console.log);
12+
13+
// Create object using buffer
14+
15+
const createWithBufferPayload: CreateObjectType = {
16+
file: Buffer.from("content".repeat(1000)),
17+
name: "testing",
18+
mimeType: MimeTypes.TEXT_PLAIN,
19+
};
20+
21+
blob.objects.create(createWithBufferPayload).then(console.log);

test/delete.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { blob } from "./index.test";
2+
3+
const objectsToDelete: string[] = [];
4+
5+
// Delete objects
6+
7+
blob.objects.delete(objectsToDelete).then(console.log);

test/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { SquareCloudBlob } from "../src";
2+
3+
export const blob = new SquareCloudBlob(
4+
process.env.SQUARECLOUD_API_KEY as string,
5+
);

test/list.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ListObjectsType } from "../src";
2+
import { blob } from "./index.test";
3+
4+
const listOptions: ListObjectsType = {
5+
prefix: "test",
6+
};
7+
8+
// List objects with filter by prefix
9+
10+
blob.objects.list(listOptions).then(console.log);
11+
12+
// List all objects
13+
14+
blob.objects.list().then(console.log);

test/mimetypes.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { MimeTypeUtil } from "../src";
2+
3+
// Get supported mime type for certain file extension
4+
5+
console.log(MimeTypeUtil.fromExtension("png")); // "image/png"
6+
console.log(MimeTypeUtil.fromExtension("potato")); // "text/plain" (unsupported, defaults to text/plain)
7+
console.log(MimeTypeUtil.fromExtension("txt")); // "text/plain"
8+
console.log(MimeTypeUtil.fromExtension("wav")); // "audio/wav"
9+
console.log(MimeTypeUtil.fromExtension("md")); // "text/plain" (unsupported, defaults to text/plain)
10+
console.log(MimeTypeUtil.fromExtension("json")); // "application/json"

0 commit comments

Comments
 (0)