Skip to content

Commit 7789b46

Browse files
committed
fix(test): fix test command and wrong env var
1 parent 4a4af65 commit 7789b46

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

packages/aws-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"lint": "eslint --fix-dry-run",
3535
"presemantic-release": "pnpm run build",
3636
"semantic-release": "semantic-release",
37-
"test": "jest",
37+
"test": "jest \"\\.spec\\.ts\"",
3838
"test-integrations": "jest \"\\.integration\\.ts\" --forceExit",
3939
"test:watch": "pnpm run test -- --watch"
4040
},

servers/shareable-lists-api/jest.setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ process.env.APOLLO_GRAPH_REF = '';
1414
process.env.AWS_ACCESS_KEY_ID = 'fake-id';
1515
process.env.AWS_SECRET_ACCESS_KEY = 'fake-key';
1616
process.env.AWS_DEFAULT_REGION = 'us-east-1';
17+
process.env.NODE_ENV = 'test';

servers/shareable-lists-api/src/background/ExportDataService.integration.ts

+55-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
import { ExportDataService, ListExport } from './ExportDataService';
2-
import { conn as db } from '../database/client';
2+
import { client, conn as db } from '../database/client';
33
import config from '../config';
44
import { S3Bucket, cleanupS3Bucket } from '@pocket-tools/aws-utils';
55
import { GetObjectCommand, GetObjectCommandOutput } from '@aws-sdk/client-s3';
66
import { eventBridgeClient } from '../aws/eventBridgeClient';
77
import path from 'path';
8+
import {
9+
createShareableListHelper,
10+
clearDb,
11+
createShareableListItemHelper,
12+
} from '../test/helpers';
813

9-
describe('AnnotationsExportService', () => {
10-
const userId = 12345;
14+
describe('ExportDataService', () => {
15+
const userId = 3483487;
1116
const encodedId = '4a5b3c';
1217
const bucket = new S3Bucket(config.export.bucket.name, {
1318
region: config.aws.region,
1419
endpoint: config.aws.endpoint,
1520
});
1621
const conn = db();
22+
const prisma = client();
1723
beforeAll(async () => {
1824
await cleanupS3Bucket(bucket);
25+
await createShareableListHelper(prisma, {
26+
userId,
27+
title: 'Empty list',
28+
});
29+
const someList = await createShareableListHelper(prisma, {
30+
userId,
31+
title: 'List of Stuff!',
32+
});
33+
await Promise.all(
34+
[...Array(40).keys()].map((ix) =>
35+
createShareableListItemHelper(prisma, {
36+
list: someList,
37+
sortOrder: ix,
38+
}),
39+
),
40+
);
1941
});
2042
afterAll(async () => {
2143
await cleanupS3Bucket(bucket);
44+
await clearDb(prisma);
2245
await conn.destroy();
2346
});
2447
it('passes a smoke test', async () => {
@@ -33,25 +56,45 @@ describe('AnnotationsExportService', () => {
3356
const exportedFiles = await bucket.listAllObjects(
3457
path.join(config.export.bucket.partsPrefix, encodedId, 'collections'),
3558
);
59+
expect(exportedFiles).toIncludeSameMembers([
60+
'parts/4a5b3c/collections/empty-list.json',
61+
'parts/4a5b3c/collections/list-of-stuff.json',
62+
]);
3663
// More than 1 file written to proper path
3764
expect(exportedFiles.length).toBeGreaterThan(1);
38-
const getObject = new GetObjectCommand({
39-
Key: exportedFiles[0],
40-
Bucket: config.export.bucket.name,
65+
const getList = async (key: string) => {
66+
const getObject = new GetObjectCommand({
67+
Key: key,
68+
Bucket: config.export.bucket.name,
69+
});
70+
const result: GetObjectCommandOutput = await bucket.s3.send(getObject);
71+
const body: ListExport = JSON.parse(
72+
(await result.Body?.transformToString()) ?? '{}',
73+
);
74+
return body;
75+
};
76+
const emptyList = await getList('parts/4a5b3c/collections/empty-list.json');
77+
expect(emptyList).toMatchObject({
78+
createdAt: expect.toBeDateString(),
79+
description: expect.toBeString(),
80+
title: expect.toBeString(),
81+
slug: expect.toBeString(),
82+
83+
items: expect.toBeArrayOfSize(0),
4184
});
42-
const result: GetObjectCommandOutput = await bucket.s3.send(getObject);
43-
const body: ListExport = JSON.parse(
44-
(await result.Body?.transformToString()) ?? '{}',
85+
const listOfStuff = await getList(
86+
'parts/4a5b3c/collections/list-of-stuff.json',
4587
);
46-
// Has the slug in the filename
47-
expect(exportedFiles[0]).toMatch(body.slug);
4888
// Has expected data shape
49-
expect(body).toMatchObject({
89+
expect(listOfStuff).toMatchObject({
5090
createdAt: expect.toBeDateString(),
5191
description: expect.toBeString(),
5292
title: expect.toBeString(),
5393
slug: expect.toBeString(),
5494
// At least one
95+
items: expect.toBeArrayOfSize(40),
96+
});
97+
expect(listOfStuff).toMatchObject({
5598
items: expect.arrayContaining([
5699
{
57100
excerpt: expect.toBeString(),

0 commit comments

Comments
 (0)