This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
335 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{ | ||
"presets": ["es2015", "stage-0"], | ||
"plugins": ["transform-runtime"] | ||
"plugins": ["transform-runtime"], | ||
"env": { | ||
"development": { | ||
"presets": [ | ||
"power-assert" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import assert from 'assert' | ||
import sinon from 'sinon' | ||
import { handle } from 'api/getComponents' | ||
import { Components, Component } from 'model/components' | ||
|
||
describe('getComponents', () => { | ||
afterEach(() => { | ||
Components.prototype.all.restore() | ||
}) | ||
|
||
it('should return a list of components', async () => { | ||
const components = [ | ||
new Component('2', undefined, undefined, undefined, 2), | ||
new Component('1', undefined, undefined, undefined, 1) | ||
] | ||
sinon.stub(Components.prototype, 'all').returns(components) | ||
|
||
return await handle({}, null, (error, result) => { | ||
assert(error === null) | ||
assert(result === JSON.stringify([{componentID: '1', order: 1}, {componentID: '2', order: 2}])) | ||
}) | ||
}) | ||
|
||
it('should return error on exception thrown', async () => { | ||
sinon.stub(Components.prototype, 'all').throws() | ||
return await handle({}, null, (error, result) => { | ||
assert(error.match(/Error/)) | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import assert from 'assert' | ||
import AWS from 'aws-sdk-mock' | ||
import ComponentsStore from 'db/components' | ||
|
||
describe('ComponentsStore', () => { | ||
describe('getAll', () => { | ||
afterEach(() => { | ||
AWS.restore('DynamoDB.DocumentClient') | ||
}) | ||
|
||
it('should return a list of components', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'scan', (params, callback) => { | ||
callback(null, {Items: [{componentID: '1', name: '', description: '', status: '', order: 1}]}) | ||
}) | ||
const comps = await new ComponentsStore().getAll() | ||
assert(comps.length === 1) | ||
assert(comps[0].componentID === '1') | ||
assert(comps[0].description === '') | ||
}) | ||
|
||
it('should call reject on error', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'scan', (params, callback) => { | ||
callback('Error') | ||
}) | ||
|
||
let error | ||
try { | ||
await new ComponentsStore().getAll() | ||
} catch (e) { | ||
error = e | ||
} | ||
assert(error.message.match(/Error/)) | ||
}) | ||
}) | ||
|
||
describe('getByID', () => { | ||
afterEach(() => { | ||
AWS.restore('DynamoDB.DocumentClient') | ||
}) | ||
|
||
it('should return a component', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'query', (params, callback) => { | ||
callback(null, {Items: [{componentID: '1', name: '', description: '', status: '', order: 1}]}) | ||
}) | ||
const comps = await new ComponentsStore().getByID('1') | ||
assert(comps.length === 1) | ||
assert(comps[0].componentID === '1') | ||
assert(comps[0].description === '') | ||
}) | ||
|
||
it('should call reject on error', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'query', (params, callback) => { | ||
callback('Error') | ||
}) | ||
|
||
let error | ||
try { | ||
await new ComponentsStore().getByID() | ||
} catch (e) { | ||
error = e | ||
} | ||
assert(error.message.match(/Error/)) | ||
}) | ||
}) | ||
|
||
describe('update', () => { | ||
afterEach(() => { | ||
AWS.restore('DynamoDB.DocumentClient') | ||
}) | ||
|
||
it('should update the component', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'update', (params, callback) => { | ||
callback(null, {Attributes: {componentID: '1', name: '', description: '', status: '', order: 1}}) | ||
}) | ||
const comp = await new ComponentsStore().update('1', '', '', '', 1) | ||
assert(comp.componentID === '1') | ||
assert(comp.description === '') | ||
}) | ||
|
||
it('should return error on exception thrown', async () => { | ||
AWS.mock('DynamoDB.DocumentClient', 'update', (params, callback) => { | ||
callback('Error') | ||
}) | ||
|
||
let error | ||
try { | ||
await new ComponentsStore().update('1', '', '', '', 1) | ||
} catch (e) { | ||
error = e | ||
} | ||
assert(error.message.match(/Error/)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.