Skip to content

Commit

Permalink
update changelog, fix readme, add reject test for each method
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelvilche committed Dec 6, 2019
1 parent fdfbada commit bb1ba6f
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 49 deletions.
10 changes: 0 additions & 10 deletions CHANGELOG.md
Expand Up @@ -6,13 +6,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.0] - 2019-12-06
### Added
- add `putObject` mehtod
- add `deleteObject` mehtod
- add `listObjects` mehtod
- add `listBuckets` mehtod
- add `createBucket` mehtod
- add `deleteBucket` mehtod

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -32,7 +32,7 @@ const putObjectParams = {

const s3Response = S3.putObject(putObjectParams);

return s3Response.then(respponse => {
return s3Response.then(response => {
// do some stuf with the success
}).cath(err => {
// do some stuf with the error
Expand Down
160 changes: 122 additions & 38 deletions tests/s3-test.js
@@ -1,16 +1,16 @@
'use strict';

const assert = require('assert');
const sandbox = require('sinon').createSandbox();
const sinon = require('sinon');

const s3Wrapper = require('../lib/s3Wrapper');

const S3 = require('./../lib/s3');
const S3 = require('../lib/s3');

describe('S3', () => {

afterEach(() => {
sandbox.restore();
sinon.restore();
});

const s3Params = {
Expand All @@ -21,148 +21,232 @@ describe('S3', () => {

context('getObject', () => {

it('should return a promise with the same params calling to getObject method', async () => {
it('Should return a promise with the same params calling to getObject method', async () => {

sandbox.stub(s3Wrapper, 'getObject').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'getObject').returns({ promise: () => Promise.resolve(s3Params) });

const getObjectInstance = await S3.getObject(s3Params);

assert.deepStrictEqual(getObjectInstance, s3Params);
});

it('should call with the same params to getObject method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

sandbox.stub(s3Wrapper, 'getObject').returns({ promise: () => Promise.resolve(s3Params) });
const message = 'random message error';

sinon.stub(s3Wrapper, 'getObject').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.getObject(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to getObject method', async () => {

sinon.stub(s3Wrapper, 'getObject').returns({ promise: () => Promise.resolve(s3Params) });

await S3.getObject(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.getObject, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.getObject, s3Params);
});
});

context('putObject', () => {

it('should return a promise with the same params calling to putObject method', async () => {
it('Should return a promise with the same params calling to putObject method', async () => {

sandbox.stub(s3Wrapper, 'putObject').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'putObject').returns({ promise: () => Promise.resolve(s3Params) });

const putObjectInstance = await S3.putObject(s3Params);

assert.deepStrictEqual(putObjectInstance, s3Params);
});

it('should call with the same params to putObject method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

const message = 'random message error';

sinon.stub(s3Wrapper, 'putObject').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.putObject(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to putObject method', async () => {

sandbox.stub(s3Wrapper, 'putObject').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'putObject').returns({ promise: () => Promise.resolve(s3Params) });

await S3.putObject(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.putObject, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.putObject, s3Params);
});
});

context('deleteObject', () => {

it('should return a promise with the same params calling to deleteObject method', async () => {
it('Should return a promise with the same params calling to deleteObject method', async () => {

sandbox.stub(s3Wrapper, 'deleteObject').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'deleteObject').returns({ promise: () => Promise.resolve(s3Params) });

const deleteObjectInstance = await S3.deleteObject(s3Params);

assert.deepStrictEqual(deleteObjectInstance, s3Params);
});

it('should call with the same params to deleteObject method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

const message = 'random message error';

sinon.stub(s3Wrapper, 'deleteObject').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.deleteObject(s3Params), {
name: 'Error',
message
});
});

sandbox.stub(s3Wrapper, 'deleteObject').returns({ promise: () => Promise.resolve(s3Params) });
it('Should call with the same params to deleteObject method', async () => {

sinon.stub(s3Wrapper, 'deleteObject').returns({ promise: () => Promise.resolve(s3Params) });

await S3.deleteObject(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.deleteObject, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.deleteObject, s3Params);
});
});

context('listObjects', () => {

it('should return a promise with the same params calling to listObjects method', async () => {
it('Should return a promise with the same params calling to listObjects method', async () => {

sandbox.stub(s3Wrapper, 'listObjects').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'listObjects').returns({ promise: () => Promise.resolve(s3Params) });

const listObjectsInstance = await S3.listObjects(s3Params);

assert.deepStrictEqual(listObjectsInstance, s3Params);
});

it('should call with the same params to listObjects method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

const message = 'random message error';

sandbox.stub(s3Wrapper, 'listObjects').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'listObjects').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.listObjects(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to listObjects method', async () => {

sinon.stub(s3Wrapper, 'listObjects').returns({ promise: () => Promise.resolve(s3Params) });

await S3.listObjects(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.listObjects, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.listObjects, s3Params);
});
});

context('listBuckets', () => {

it('should return a promise with the same params calling to listBuckets method', async () => {
it('Should return a promise with the same params calling to listBuckets method', async () => {

sandbox.stub(s3Wrapper, 'listBuckets').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'listBuckets').returns({ promise: () => Promise.resolve(s3Params) });

const listBucketsInstance = await S3.listBuckets(s3Params);

assert.deepStrictEqual(listBucketsInstance, s3Params);
});

it('should call with the same params to listBuckets method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

const message = 'random message error';

sandbox.stub(s3Wrapper, 'listBuckets').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'listBuckets').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.listBuckets(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to listBuckets method', async () => {

sinon.stub(s3Wrapper, 'listBuckets').returns({ promise: () => Promise.resolve(s3Params) });

await S3.listBuckets(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.listBuckets, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.listBuckets, s3Params);
});
});

context('createBucket', () => {

it('should return a promise with the same params calling to createBucket method', async () => {
it('Should return a promise with the same params calling to createBucket method', async () => {

sandbox.stub(s3Wrapper, 'createBucket').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'createBucket').returns({ promise: () => Promise.resolve(s3Params) });

const createBucketInstance = await S3.createBucket(s3Params);

assert.deepStrictEqual(createBucketInstance, s3Params);
});

it('should call with the same params to createBucket method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

sandbox.stub(s3Wrapper, 'createBucket').returns({ promise: () => Promise.resolve(s3Params) });
const message = 'random message error';

sinon.stub(s3Wrapper, 'createBucket').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.createBucket(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to createBucket method', async () => {

sinon.stub(s3Wrapper, 'createBucket').returns({ promise: () => Promise.resolve(s3Params) });

await S3.createBucket(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.createBucket, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.createBucket, s3Params);
});
});

context('deleteBucket', () => {

it('should return a promise with the same params calling to deleteBucket method', async () => {
it('Should return a promise with the same params calling to deleteBucket method', async () => {

sandbox.stub(s3Wrapper, 'deleteBucket').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'deleteBucket').returns({ promise: () => Promise.resolve(s3Params) });

const deleteBucketInstance = await S3.deleteBucket(s3Params);

assert.deepStrictEqual(deleteBucketInstance, s3Params);
});

it('should call with the same params to deleteBucket method', async () => {
it('Should rejects the promise calling to getObject method', async () => {

const message = 'random message error';

sinon.stub(s3Wrapper, 'deleteBucket').returns({ promise: () => Promise.reject(new Error(message)) });

assert.rejects(S3.deleteBucket(s3Params), {
name: 'Error',
message
});
});

it('Should call with the same params to deleteBucket method', async () => {

sandbox.stub(s3Wrapper, 'deleteBucket').returns({ promise: () => Promise.resolve(s3Params) });
sinon.stub(s3Wrapper, 'deleteBucket').returns({ promise: () => Promise.resolve(s3Params) });

await S3.deleteBucket(s3Params);

sandbox.assert.calledWithExactly(s3Wrapper.deleteBucket, s3Params);
sinon.assert.calledWithExactly(s3Wrapper.deleteBucket, s3Params);
});
});
});

0 comments on commit bb1ba6f

Please sign in to comment.