mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
feat: tests
This commit is contained in:
@@ -24,29 +24,27 @@ import {expect} from 'chai';
|
||||
import chai from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import chaiSpies from 'chai-spies';
|
||||
import {suite, test} from '@testdeck/mocha';
|
||||
import moment from 'moment';
|
||||
import {Bulk} from '../src/bulk.js';
|
||||
import {Client} from '../src/client.js';
|
||||
import {BulkWithMultipleTypesError} from '../src/errors.js';
|
||||
import {HttpClient} from '../src/http-client.js';
|
||||
import {HttpClient, Bulk, Client, BulkWithMultipleTypesError} from '../src/index.js';
|
||||
|
||||
chai.should();
|
||||
chai.use(chaiSpies);
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
const sandbox = chai.spy.sandbox();
|
||||
describe('Bulk', function () {
|
||||
const sandbox = chai.spy.sandbox();
|
||||
|
||||
const bulkAddRoute = new SCBulkAddRoute();
|
||||
const bulkDoneRoute = new SCBulkDoneRoute();
|
||||
const bulkAddRoute = new SCBulkAddRoute();
|
||||
const bulkDoneRoute = new SCBulkDoneRoute();
|
||||
|
||||
const httpClient = new HttpClient();
|
||||
const client = new Client(httpClient, 'http://localhost');
|
||||
const httpClient = new HttpClient();
|
||||
const client = new Client(httpClient, 'http://localhost');
|
||||
|
||||
@suite()
|
||||
export class BulkSpec {
|
||||
@test
|
||||
async add() {
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
})
|
||||
|
||||
it('should add', async function () {
|
||||
sandbox.on(client, 'invokeRoute', () => {
|
||||
return {};
|
||||
});
|
||||
@@ -82,10 +80,9 @@ export class BulkSpec {
|
||||
},
|
||||
dish,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
async addFails() {
|
||||
it('should fail add', async function () {
|
||||
const bulk = new Bulk(SCThingType.Dish, client, {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
source: 'foo',
|
||||
@@ -108,15 +105,10 @@ export class BulkSpec {
|
||||
uid: 'foo',
|
||||
};
|
||||
|
||||
return bulk.add(message).should.be.rejectedWith(BulkWithMultipleTypesError);
|
||||
}
|
||||
await bulk.add(message).should.be.rejectedWith(BulkWithMultipleTypesError);
|
||||
});
|
||||
|
||||
async after() {
|
||||
sandbox.restore();
|
||||
}
|
||||
|
||||
@test
|
||||
async construct() {
|
||||
it('should construct', function () {
|
||||
expect(() => {
|
||||
return new Bulk(SCThingType.Dish, client, {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
@@ -126,10 +118,9 @@ export class BulkSpec {
|
||||
uid: 'bar',
|
||||
});
|
||||
}).not.to.throw();
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
async done() {
|
||||
it('should done', async function () {
|
||||
sandbox.on(client, 'invokeRoute', () => {
|
||||
return {};
|
||||
});
|
||||
@@ -149,5 +140,5 @@ export class BulkSpec {
|
||||
expect(client.invokeRoute).to.have.been.first.called.with(bulkDoneRoute, {
|
||||
UID: 'bar',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user