UNPKG

dbl-coins-invest

Version:

Sharade DBL package over other coins invest services

155 lines (136 loc) 4.36 kB
import AlertsService from "../src/dynamodb/alerts"; import 'rxjs/add/operator/mergeMap' const mock = require('./fixtures/alerts-mock.json'); const expect = require('chai').expect; const dynamoose = require('dynamoose'); const USER_SUB = 'ff05be11-2673-409d-80a5-6c50c21acce1'; const asyncTimeout = 10000; const uuId = require('uuid').v4; const dynamoTableName = 'notification-configs-test'; describe('Create And Load Alerts', () => { let alertsService = new AlertsService(USER_SUB); let loadedAlerts; it('Load fixtures', (done) => { mock.forEach((m) => { m.id = uuId(); }); alertsService.batchPut(mock) .subscribe((response) => { expect(response.length).to.be.an('undefined'); done() }, (error) => { console.error(error); }); }); it('Load all alert configs', (done) => { alertsService.getAll() .subscribe((response) => { expect(response.length).to.be.eql(mock.length); done() }, (error) => { console.error(error); }); // done(); }).timeout(asyncTimeout); it('Remove one', (done) => { alertsService.delete(mock.pop()) .subscribe((response) => { done() }, (error) => { console.error(error); }); // done(); }).timeout(asyncTimeout); it('Remove many', (done) => { alertsService.batchDelete(mock) .subscribe((response) => { done() }, (error) => { console.error(error); }); // done(); }).timeout(asyncTimeout); let alert = { "id": uuId(), "userSub": USER_SUB, "userData": { "firstName": "Daniel_1", "lastName": "Ostr_1", "email": "danduh+test1@gmail.com" }, "type": "absPrice", "isActive": true, "idleInterval": 1800, "lastNotified": 13234234234, "notificationStatus": "failed", "config": { baseCurrency: "USD", coinId: "BTC", direction: false, targetPrice: 1400, type: "absPrice" } }; it('Create One', (done) => { alertsService .create(alert) .subscribe((response) => { expect(response.id).to.be.eql(alert.id); done() }, (error) => { console.error(error); }); }).timeout(asyncTimeout); it('Get One', (done) => { alertsService .getById(alert.id) .subscribe((response) => { expect(response.id).to.be.eql(alert.id); done() }, (error) => { console.error(error); }); }).timeout(asyncTimeout); it('Get by Type', (done) => { alertsService .getByType('absPrice') .subscribe((response) => { expect(response.length).to.be.eql(1); expect(response[0].userSub).to.be.eql(alert.userSub); done() }, (error) => { console.error(error); }); }).timeout(asyncTimeout); it('Update One Status', (done) => { alert.isActive = false; alertsService .update(alert) .subscribe((response) => { expect(response.isActive).to.be.eql(alert.isActive); done() }, (error) => { console.error(error); }); }).timeout(asyncTimeout); it('Update + Add property', (done) => { alertsService .update(alert, {$PUT: {idleInterval: 10000}}) .subscribe((response) => { expect(response.idleInterval).to.be.eql(10000); done() }, (error) => { console.error(error); }); }).timeout(asyncTimeout); it('Remove Table', (done) => { let dynamoDB = dynamoose.ddb(); dynamoDB.deleteTable({TableName: dynamoTableName}, (err, resp) => { if (err) { console.error(err); } console.log(resp); done() }) }) });