Skip to content

Commit 6fe7aa5

Browse files
Merge pull request #323 from opencomponents/upgrade-aws
Upgrade aws
2 parents a199e4b + 516cd33 commit 6fe7aa5

File tree

6 files changed

+233
-355
lines changed

6 files changed

+233
-355
lines changed

packages/oc-s3-storage-adapter/__mocks__/aws-sdk.js renamed to packages/oc-s3-storage-adapter/__mocks__/@aws-sdk/client-s3.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const awsSdk = jest.genMockFromModule('aws-sdk');
1+
const awsSdk = jest.genMockFromModule('@aws-sdk/client-s3');
2+
const stream = require('stream');
23
const _config = { update: jest.fn() };
34

45
jest.mock('fs-extra', () => {
@@ -31,7 +32,7 @@ let cachedTxt = 0;
3132
let cachedJson = 0;
3233
const _S3 = class {
3334
constructor() {
34-
this.getObject = jest.fn((val, cb) => {
35+
this.getObject = jest.fn(val => {
3536
cachedTxt++;
3637
cachedJson++;
3738
const contents = {
@@ -47,10 +48,14 @@ const _S3 = class {
4748
};
4849

4950
const testResult = contents[val.Key];
50-
cb(testResult.error || null, { Body: testResult.content });
51+
if (testResult.error) throw testResult.error;
52+
53+
return {
54+
Body: stream.Readable.from([Buffer.from(String(testResult.content))])
55+
};
5156
});
5257

53-
this.listObjects = jest.fn((val, cb) => {
58+
this.listObjects = jest.fn(val => {
5459
const CommonPrefixes =
5560
val.Bucket === 'my-empty-bucket'
5661
? []
@@ -63,32 +68,27 @@ const _S3 = class {
6368
}
6469
];
6570

66-
cb(null, { CommonPrefixes });
71+
return Promise.resolve({ CommonPrefixes });
6772
});
6873

69-
this.upload = jest.fn(data => {
70-
return {
71-
send: jest.fn(cb => {
72-
let error;
73-
if (data && data.Key && data.Key.indexOf('error') >= 0) {
74-
if (data.Key.indexOf('throw') >= 0) {
75-
throw new Error('sorry');
76-
}
74+
this.putObject = jest.fn(data => {
75+
if (data && data.Key && data.Key.indexOf('error') >= 0) {
76+
if (data.Key.indexOf('throw') >= 0) {
77+
throw new Error('sorry');
78+
}
7779

78-
error = {
79-
code: 1234,
80-
message: 'an error message',
81-
retryable: true,
82-
statusCode: 500,
83-
time: new Date(),
84-
hostname: 'hostname',
85-
region: 'us-west2'
86-
};
87-
}
80+
throw {
81+
code: 1234,
82+
message: 'an error message',
83+
retryable: true,
84+
statusCode: 500,
85+
time: new Date(),
86+
hostname: 'hostname',
87+
region: 'us-west2'
88+
};
89+
}
8890

89-
cb(error, data);
90-
})
91-
};
91+
return data;
9292
});
9393
}
9494
};

packages/oc-s3-storage-adapter/__test__/config.test.js

Lines changed: 0 additions & 100 deletions
This file was deleted.

packages/oc-s3-storage-adapter/__test__/privateFilesExclusion.test.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { fromPromise } = require('universalify');
12
const s3 = require('../lib');
23

34
jest.mock('async', () => {
@@ -26,22 +27,16 @@ test('put directory recognizes server.js and .env to be private', done => {
2627

2728
const client = new s3(options);
2829

29-
client.putDir('.', '.', (_, mockResult) => {
30-
const separators = ['\\', '/'];
31-
for (let separator of separators) {
32-
expect(mockResult[`.${separator}.env`].res.ACL).toBe(
33-
'authenticated-read'
34-
);
35-
expect(mockResult[`.${separator}server.js`].res.ACL).toBe(
36-
'authenticated-read'
37-
);
38-
expect(mockResult[`.${separator}package.json`].res.ACL).toBe(
39-
'public-read'
40-
);
41-
expect(mockResult[`.${separator}template.js`].res.ACL).toBe(
42-
'public-read'
43-
);
44-
}
30+
fromPromise(client.putDir)('.', '.', (_, mockResult) => {
31+
const serverMock = mockResult.find(x => x.Key === `./server.js`);
32+
const envMock = mockResult.find(x => x.Key === './.env');
33+
const packageMock = mockResult.find(x => x.Key === './package.json');
34+
const templateMock = mockResult.find(x => x.Key === './template.js');
35+
36+
expect(serverMock.ACL).toBe('authenticated-read');
37+
expect(envMock.ACL).toBe('authenticated-read');
38+
expect(packageMock.ACL).toBe('public-read');
39+
expect(templateMock.ACL).toBe('public-read');
4540

4641
done();
4742
});

0 commit comments

Comments
 (0)