Skip to content

Commit 0a4b80c

Browse files
committed
refactored test according to previous PRs comment
1 parent 0873698 commit 0a4b80c

File tree

1 file changed

+72
-74
lines changed

1 file changed

+72
-74
lines changed

spec/test.spec.js

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -316,89 +316,87 @@ describe('S3Adapter tests', () => {
316316
});
317317

318318
describe('getFileLocation', () => {
319-
['http://example.com/files', () => 'http://example.com/files'].forEach((baseUrl) => {
320-
const testConfig = {
321-
mount: 'http://my.server.com/parse',
322-
applicationId: 'xxxx',
319+
const testConfig = {
320+
mount: 'http://my.server.com/parse',
321+
applicationId: 'xxxx',
322+
};
323+
let options;
324+
325+
beforeEach(() => {
326+
options = {
327+
presignedUrl: false,
328+
directAccess: true,
329+
bucketPrefix: 'foo/bar/',
330+
baseUrl: 'http://example.com/files',
323331
};
324-
let options;
325-
326-
beforeEach(() => {
327-
options = {
328-
presignedUrl: false,
329-
directAccess: true,
330-
bucketPrefix: 'foo/bar/',
331-
baseUrl,
332-
};
333-
});
332+
});
334333

335-
it('should get using the baseUrl', () => {
336-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
337-
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://example.com/files/foo/bar/test.png');
338-
});
334+
it('should get using the baseUrl', () => {
335+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
336+
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://example.com/files/foo/bar/test.png');
337+
});
339338

340-
it('when use presigned URL should use S3 \'getObject\' operation', () => {
341-
options.presignedUrl = true;
342-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
343-
const originalS3Client = s3._s3Client;
344-
let getSignedUrlOperation = '';
345-
s3._s3Client = {
346-
getSignedUrl: (operation, params, callback) => {
347-
getSignedUrlOperation = operation;
348-
return originalS3Client.getSignedUrl(operation, params, callback);
349-
},
350-
};
339+
it('when use presigned URL should use S3 \'getObject\' operation', () => {
340+
options.presignedUrl = true;
341+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
342+
const originalS3Client = s3._s3Client;
343+
let getSignedUrlOperation = '';
344+
s3._s3Client = {
345+
getSignedUrl: (operation, params, callback) => {
346+
getSignedUrlOperation = operation;
347+
return originalS3Client.getSignedUrl(operation, params, callback);
348+
},
349+
};
351350

352-
s3.getFileLocation(testConfig, 'test.png');
353-
expect(getSignedUrlOperation).toBe('getObject');
354-
});
351+
s3.getFileLocation(testConfig, 'test.png');
352+
expect(getSignedUrlOperation).toBe('getObject');
353+
});
355354

356-
it('should get using the baseUrl and amazon using presigned URL', () => {
357-
options.presignedUrl = true;
358-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
359-
360-
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
361-
expect(fileLocation).toMatch(/^http:\/\/example.com\/files\/foo\/bar\/test.png\?/);
362-
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2F\w{2}-\w{1,9}-\d%2Fs3%2Faws4_request/);
363-
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);
364-
expect(fileLocation).toMatch(/X-Amz-Signature=.{64}/);
365-
expect(fileLocation).toMatch(/X-Amz-Expires=\d{1,6}/);
366-
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
367-
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
368-
});
355+
it('should get using the baseUrl and amazon using presigned URL', () => {
356+
options.presignedUrl = true;
357+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
369358

370-
it('should get direct to baseUrl', () => {
371-
options.baseUrlDirect = true;
372-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
373-
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://example.com/files/test.png');
374-
});
359+
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
360+
expect(fileLocation).toMatch(/^http:\/\/example.com\/files\/foo\/bar\/test.png\?/);
361+
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2F\w{2}-\w{1,9}-\d%2Fs3%2Faws4_request/);
362+
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);
363+
expect(fileLocation).toMatch(/X-Amz-Signature=.{64}/);
364+
expect(fileLocation).toMatch(/X-Amz-Expires=\d{1,6}/);
365+
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
366+
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
367+
});
375368

376-
it('should get without directAccess', () => {
377-
options.directAccess = false;
378-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
379-
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://my.server.com/parse/files/xxxx/test.png');
380-
});
369+
it('should get direct to baseUrl', () => {
370+
options.baseUrlDirect = true;
371+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
372+
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://example.com/files/test.png');
373+
});
381374

382-
it('should go directly to amazon', () => {
383-
delete options.baseUrl;
384-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
385-
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('https://my-bucket.s3.amazonaws.com/foo/bar/test.png');
386-
});
375+
it('should get without directAccess', () => {
376+
options.directAccess = false;
377+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
378+
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('http://my.server.com/parse/files/xxxx/test.png');
379+
});
387380

388-
it('should go directly to amazon using presigned URL', () => {
389-
delete options.baseUrl;
390-
options.presignedUrl = true;
391-
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
392-
393-
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
394-
expect(fileLocation).toMatch(/^https:\/\/my-bucket.s3.amazonaws.com\/foo\/bar\/test.png\?/);
395-
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2Fus-east-1%2Fs3%2Faws4_request/);
396-
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);
397-
expect(fileLocation).toMatch(/X-Amz-Signature=.{64}/);
398-
expect(fileLocation).toMatch(/X-Amz-Expires=\d{1,6}/);
399-
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
400-
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
401-
});
381+
it('should go directly to amazon', () => {
382+
delete options.baseUrl;
383+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
384+
expect(s3.getFileLocation(testConfig, 'test.png')).toEqual('https://my-bucket.s3.amazonaws.com/foo/bar/test.png');
385+
});
386+
387+
it('should go directly to amazon using presigned URL', () => {
388+
delete options.baseUrl;
389+
options.presignedUrl = true;
390+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
391+
392+
const fileLocation = s3.getFileLocation(testConfig, 'test.png');
393+
expect(fileLocation).toMatch(/^https:\/\/my-bucket.s3.amazonaws.com\/foo\/bar\/test.png\?/);
394+
expect(fileLocation).toMatch(/X-Amz-Credential=accessKey%2F\d{8}%2Fus-east-1%2Fs3%2Faws4_request/);
395+
expect(fileLocation).toMatch(/X-Amz-Date=\d{8}T\d{6}Z/);
396+
expect(fileLocation).toMatch(/X-Amz-Signature=.{64}/);
397+
expect(fileLocation).toMatch(/X-Amz-Expires=\d{1,6}/);
398+
expect(fileLocation).toContain('X-Amz-Algorithm=AWS4-HMAC-SHA256');
399+
expect(fileLocation).toContain('X-Amz-SignedHeaders=host');
402400
});
403401
});
404402

0 commit comments

Comments
 (0)