Skip to content

Commit

Permalink
Resolve failing domains test and exclude test data file from eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Janson Bunce committed Oct 31, 2024
1 parent d86c184 commit 1b44a5b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backend/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
es6: true
node: true
parser: '@typescript-eslint/parser'
ignorePatterns: [dist/**]
ignorePatterns: [dist/**,dmzLzSyncTestDAta.ts]

Check failure on line 6 in backend/.eslintrc.yml

View workflow job for this annotation

GitHub Actions / lint

6:26 [commas] too few spaces after comma

Check failure on line 6 in backend/.eslintrc.yml

View workflow job for this annotation

GitHub Actions / lint

6:26 [commas] too few spaces after comma
extends:
- plugin:prettier/recommended
- plugin:@typescript-eslint/eslint-recommended
Expand Down
7 changes: 4 additions & 3 deletions backend/src/api/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const export_ = wrapHandler(async (event) => {
res.products = Object.values(products).join(', ');
return res;
});
const { url } = await client.saveCSV(
const res = await client.saveCSV(
Papa.unparse({
fields: [
'name',
Expand All @@ -247,13 +247,14 @@ export const export_ = wrapHandler(async (event) => {
],
data: result
}),
'domains'
'domains',
process.env.EXPORT_BUCKET_NAME
);

return {
statusCode: 200,
body: JSON.stringify({
url
url: res.url
})
};
});
Expand Down
4 changes: 3 additions & 1 deletion backend/src/tasks/__mocks__/s3-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const saveCSV = jest.fn(() => 'http://mock_url');
export const saveCSV = jest.fn(() => {
return { url: 'http://mock_url' };
});
export const listReports = jest.fn(() => ({ Contents: 'report content' }));
export const exportReport = jest.fn(() => 'report_url');

Expand Down
8 changes: 4 additions & 4 deletions backend/src/tasks/s3-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ class S3Client {
name: string = '',
bucket: string = 'crossfeed-local-exports'
) {
const bucketToUse = bucket ?? process.env.EXPORT_BUCKET_NAME;
try {
const Key = `${Math.random()}/${name}-${new Date().toISOString()}.csv`;
const params = {
Bucket: bucket ?? process.env.EXPORT_BUCKET_NAME,
Bucket: bucketToUse,
Key,
Body: body,
ContentType: 'text/csv'
};
await this.s3.putObject(params).promise();
const url = await this.s3.getSignedUrlPromise('getObject', {
Bucket: bucket,
Bucket: bucketToUse,
Key,
Expires: 60 * 5 // 5 minutes
});

// Do this so exports are accessible when running locally.
if (this.isLocal) {
console.log(url.replace('minio:9000', 'localhost:9000'));
return { url: url.replace('minio:9000', 'localhost:9000'), key: Key };
}
return { url, key: Key };
return { url: url, key: Key, bucket: bucketToUse };
} catch (e) {
console.error(e);
throw e;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/tasks/test/s3-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jest.mock('aws-sdk', () => ({
describe('saveCSV', () => {
test('gets url', async () => {
const client = new S3Client();
const result = await client.saveCSV('data');
expect(result).toEqual('http://signed_url');
const { url } = await client.saveCSV('data');
expect(url).toEqual('http://signed_url');
expect(putObject).toBeCalled();
});
});
Expand Down

0 comments on commit 1b44a5b

Please sign in to comment.