Skip to content

Commit 56cfb96

Browse files
committed
config(jobs): jest test workspace files has been configured, with a sample of mock files.
1 parent 675df69 commit 56cfb96

File tree

18 files changed

+2558
-204
lines changed

18 files changed

+2558
-204
lines changed

packages/utils/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function safePromise<T>(promise: Promise<T>): Promise<T | Error> {
1212
try {
1313
return await promise;
1414
} catch (error) {
15-
return error instanceof Error ? error : new Error("unkown");
15+
return error instanceof Error ? error : new Error(String(error));
1616
}
1717
}
1818

pnpm-lock.yaml

Lines changed: 2373 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/jobs/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ENVIRONMENT="local"
2+
13
PG_USER='postgres'
24
PG_PASSWORD='litespace'
35
PG_HOST='localhost'
@@ -7,7 +9,6 @@ DATABASE_URL=postgres://postgres:litespace@localhost:5432/litespace
79

810
TELEGRAM_TOKEN="<TOKEN>"
911
TELEGRAM_CHAT="-4520756689"
10-
ENVIRONMENT="local"
1112
ADMIN_PHONE_NUMBER="01012345678"
1213

1314
SPACES_BUCKET_NAME='litespace-staging-assets'

services/jobs/.env.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ENVIRONMENT="local"
2+
3+
PG_USER='postgres'
4+
PG_PASSWORD='litespace'
5+
PG_HOST='localhost'
6+
PG_PORT='5432'
7+
PG_DATABASE='test'
8+
DATABASE_URL=postgres://postgres:litespace@localhost:5432/test
9+
10+
TELEGRAM_TOKEN="<TOKEN>"
11+
TELEGRAM_CHAT="-4520756689"
12+
ADMIN_PHONE_NUMBER="01012345678"
13+
14+
SPACES_BUCKET_NAME='litespace-staging-assets'
15+
SPACES_ACCESS_KEY='DO801AB4JH2T3GHL9MXB'
16+
SPACES_SECRET_ACCESS_KEY=''
17+
18+
BACKUP_METHOD='dump'

services/jobs/.env.test.ci

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ENVIRONMENT="local"
2+
3+
PG_USER='postgres'
4+
PG_PASSWORD='litespace'
5+
PG_HOST='postgres'
6+
PG_PORT='5432'
7+
PG_DATABASE='test'
8+
DATABASE_URL=postgres://postgres:litespace@postgres:5432/test
9+
10+
TELEGRAM_TOKEN="<TOKEN>"
11+
TELEGRAM_CHAT="-4520756689"
12+
ADMIN_PHONE_NUMBER="01012345678"
13+
14+
SPACES_BUCKET_NAME='litespace-staging-assets'
15+
SPACES_ACCESS_KEY='DO801AB4JH2T3GHL9MXB'
16+
SPACES_SECRET_ACCESS_KEY=''
17+
18+
BACKUP_METHOD='dump'

services/jobs/babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
5+
],
6+
};

services/jobs/fixtures/mocks/fs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jest.mock("fs", () => ({
2+
readFileSync: () => "",
3+
existsSync: () => true,
4+
rmSync: () => true,
5+
}));

services/jobs/fixtures/mocks/s3.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
type MockSendResponse = {
2+
Contents: Array<unknown>;
3+
};
4+
5+
class MockS3Client {
6+
constructor() {}
7+
async send(): Promise<MockSendResponse> {
8+
return { Contents: [] };
9+
}
10+
}
11+
12+
class MockPutObjectCommand {
13+
constructor() {}
14+
}
15+
16+
class MockGetObjectCommand {
17+
constructor() {}
18+
}
19+
20+
class MockListObjectsV2Command {
21+
constructor() {}
22+
}
23+
24+
function mockGetSignedUrl(): string {
25+
return "https://example.com/";
26+
}
27+
28+
jest.mock("@aws-sdk/client-s3", () => ({
29+
S3Client: MockS3Client,
30+
PutObjectCommand: MockPutObjectCommand,
31+
GetObjectCommand: MockGetObjectCommand,
32+
ListObjectsV2Command: MockListObjectsV2Command,
33+
}));
34+
35+
jest.mock("@aws-sdk/s3-request-presigner", () => ({
36+
getSignedUrl: mockGetSignedUrl,
37+
}));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jest.mock("@/lib/terminal", () => ({
2+
execute: (_: string) => {},
3+
}));

services/jobs/fixtures/setup.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { up, down } from "./shared";
2+
3+
export default async function setup() {
4+
await down();
5+
await up();
6+
}

0 commit comments

Comments
 (0)