2023-02-17 12:30:17 -06:00
|
|
|
import { OnspringClient, PagingRequest } from '../../src';
|
2023-02-13 21:02:00 -06:00
|
|
|
import { expect } from 'chai';
|
2023-02-14 23:49:18 -06:00
|
|
|
import { baseURL, apiKey } from '../mochaRootHooks';
|
2023-02-13 21:02:00 -06:00
|
|
|
|
|
|
|
|
describe('getApps', function () {
|
2023-02-14 23:49:18 -06:00
|
|
|
this.timeout(30000);
|
|
|
|
|
this.retries(3);
|
|
|
|
|
|
2023-02-14 21:21:47 -06:00
|
|
|
it('should return a paged list of apps', async function () {
|
2023-02-13 21:02:00 -06:00
|
|
|
const client = new OnspringClient(baseURL, apiKey);
|
|
|
|
|
const response = await client.getApps();
|
|
|
|
|
|
|
|
|
|
expect(response.statusCode).to.equal(200);
|
|
|
|
|
expect(response.isSuccessful).to.be.true;
|
|
|
|
|
expect(response.message).to.equal('');
|
|
|
|
|
expect(response.data).to.not.be.null;
|
|
|
|
|
|
|
|
|
|
if (response.data != null) {
|
|
|
|
|
expect(response.data.pageNumber).to.not.be.null;
|
|
|
|
|
expect(response.data.pageSize).to.not.be.null;
|
|
|
|
|
expect(response.data.totalPages).to.not.be.null;
|
|
|
|
|
expect(response.data.totalRecords).to.not.be.null;
|
|
|
|
|
expect(response.data.items).to.not.be.null;
|
|
|
|
|
|
|
|
|
|
if (response.data.items != null) {
|
|
|
|
|
expect(response.data.items.length).to.be.greaterThan(0);
|
|
|
|
|
response.data.items.forEach((item) => {
|
|
|
|
|
expect(item.id).to.not.be.null;
|
|
|
|
|
expect(item.name).to.not.be.null;
|
|
|
|
|
expect(item.href).to.not.be.null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-13 21:17:38 -06:00
|
|
|
|
2023-02-14 21:21:47 -06:00
|
|
|
it('should return a paged list of apps with with correct page size and number when passed paging request', async function () {
|
2023-02-13 21:17:38 -06:00
|
|
|
const client = new OnspringClient(baseURL, apiKey);
|
|
|
|
|
const response = await client.getApps(new PagingRequest(1, 1));
|
|
|
|
|
|
|
|
|
|
expect(response.statusCode).to.equal(200);
|
|
|
|
|
expect(response.isSuccessful).to.be.true;
|
|
|
|
|
expect(response.message).to.equal('');
|
|
|
|
|
expect(response.data).to.not.be.null;
|
|
|
|
|
|
|
|
|
|
if (response.data != null) {
|
|
|
|
|
expect(response.data.pageNumber).to.equal(1);
|
|
|
|
|
expect(response.data.pageSize).to.equal(1);
|
|
|
|
|
expect(response.data.totalPages).to.not.be.null;
|
|
|
|
|
expect(response.data.totalRecords).to.not.be.null;
|
|
|
|
|
expect(response.data.items).to.not.be.null;
|
|
|
|
|
|
|
|
|
|
if (response.data.items != null) {
|
2023-02-14 22:14:45 -06:00
|
|
|
expect(response.data.items.length).to.equal(1);
|
2023-02-13 21:17:38 -06:00
|
|
|
response.data.items.forEach((item) => {
|
|
|
|
|
expect(item.id).to.not.be.null;
|
|
|
|
|
expect(item.name).to.not.be.null;
|
|
|
|
|
expect(item.href).to.not.be.null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-13 23:24:47 -06:00
|
|
|
|
|
|
|
|
it('should return a 400 response when an invalid page size is used', async function () {
|
|
|
|
|
const client = new OnspringClient(baseURL, apiKey);
|
|
|
|
|
const response = await client.getApps({ pageNumber: 1, pageSize: 1001 });
|
|
|
|
|
|
|
|
|
|
expect(response.statusCode).to.equal(400);
|
|
|
|
|
expect(response.isSuccessful).to.be.false;
|
2023-02-14 22:14:45 -06:00
|
|
|
expect(response.message).to.not.be.undefined.and.not.be.null;
|
2023-02-13 23:24:47 -06:00
|
|
|
expect(response.data).to.be.null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return a 401 response when an invalid api key is used', async function () {
|
|
|
|
|
const client = new OnspringClient(baseURL, 'invalid');
|
|
|
|
|
const response = await client.getApps();
|
|
|
|
|
|
|
|
|
|
expect(response.statusCode).to.equal(401);
|
|
|
|
|
expect(response.isSuccessful).to.be.false;
|
|
|
|
|
expect(response.message).to.be.undefined;
|
|
|
|
|
expect(response.data).to.be.null;
|
|
|
|
|
});
|
2023-02-13 21:02:00 -06:00
|
|
|
});
|