mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
test: add tests for routes
This commit is contained in:
committed by
Rainer Killinger
parent
751693bebc
commit
d3955b3cdd
128
test/routes/bulk-route.spec.ts
Normal file
128
test/routes/bulk-route.spec.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2019, 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {
|
||||
SCBulkAddRoute,
|
||||
SCBulkDoneRoute,
|
||||
SCBulkRequest,
|
||||
SCBulkRoute,
|
||||
SCNotFoundErrorResponse,
|
||||
SCThingType
|
||||
} from '@openstapps/core';
|
||||
import {Bulk} from '../../src/storage/bulk-storage';
|
||||
import {expect} from 'chai';
|
||||
import {instance as book} from '@openstapps/core/test/resources/Book.1.json';
|
||||
import moment from 'moment';
|
||||
import {DEFAULT_TEST_TIMEOUT} from '../common';
|
||||
import {testApp} from '../tests-setup';
|
||||
|
||||
describe('Bulk routes', async function () {
|
||||
// increase timeout for the suite
|
||||
this.timeout(DEFAULT_TEST_TIMEOUT);
|
||||
|
||||
const bulkObj: Bulk = {
|
||||
expiration: moment().add(3600, 'seconds')
|
||||
.format(),
|
||||
source: 'some_source',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Book,
|
||||
uid: ''
|
||||
};
|
||||
const request: SCBulkRequest = {
|
||||
expiration: bulkObj.expiration,
|
||||
source: bulkObj.source,
|
||||
type: bulkObj.type,
|
||||
};
|
||||
const bulkRoute = new SCBulkRoute();
|
||||
const bulkAddRoute = new SCBulkAddRoute();
|
||||
const bulkDoneRoute = new SCBulkDoneRoute();
|
||||
|
||||
// afterEach(async function() {
|
||||
// TODO: Delete saved bulks
|
||||
// });
|
||||
|
||||
it('should create bulk', async function () {
|
||||
const {status, body, error} = await testApp
|
||||
.post(bulkRoute.urlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(request);
|
||||
|
||||
expect(status).to.be.equal(bulkRoute.statusCodeSuccess);
|
||||
expect(error).to.be.equal(false);
|
||||
expect(body.uid).to.be.a('string');
|
||||
expect(body).to.deep.equal({...bulkObj, uid: body.uid});
|
||||
});
|
||||
|
||||
it('should return (throw) error if a bulk with the provided UID cannot be found when adding to a bulk', async function () {
|
||||
await testApp
|
||||
.post(bulkRoute.urlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(request);
|
||||
const bulkAddRouteUrlFragment = bulkAddRoute.urlFragment.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
|
||||
|
||||
const {status} = await testApp
|
||||
.post(bulkAddRouteUrlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(book);
|
||||
|
||||
expect(status).to.be.equal(new SCNotFoundErrorResponse().statusCode);
|
||||
});
|
||||
|
||||
it('should add to a created bulk', async function () {
|
||||
const response = await testApp
|
||||
.post(bulkRoute.urlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(request);
|
||||
const bulkAddRouteUrlFragment = bulkAddRoute.urlFragment.toLocaleLowerCase().replace(':uid', response.body.uid);
|
||||
|
||||
const {status, body} = await testApp
|
||||
.post(bulkAddRouteUrlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(book);
|
||||
|
||||
expect(status).to.be.equal(bulkAddRoute.statusCodeSuccess);
|
||||
expect(body).to.be.deep.equal({});
|
||||
});
|
||||
|
||||
it('should return (throw) error if a bulk with the provided UID cannot be found when closing a bulk (done)', async function () {
|
||||
await testApp
|
||||
.post(bulkRoute.urlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(request);
|
||||
const bulkDoneRouteUrlFragment = bulkDoneRoute.urlFragment.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
|
||||
|
||||
const {status} = await testApp
|
||||
.post(bulkDoneRouteUrlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send({});
|
||||
|
||||
expect(status).to.be.equal(new SCNotFoundErrorResponse().statusCode);
|
||||
});
|
||||
|
||||
it ('should close the bulk (done)', async function () {
|
||||
const response = await testApp
|
||||
.post(bulkRoute.urlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(request);
|
||||
const bulkDoneRouteUrlFragment = bulkDoneRoute.urlFragment.toLocaleLowerCase().replace(':uid', response.body.uid);
|
||||
|
||||
const response2 = await testApp
|
||||
.post(bulkDoneRouteUrlFragment)
|
||||
.set('Content-Type', 'application/json')
|
||||
.send({});
|
||||
|
||||
expect(response2.status).to.be.equal(bulkDoneRoute.statusCodeSuccess);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user