Skip to content

Commit

Permalink
test: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
y1j2x34 committed Jun 11, 2018
1 parent 6934204 commit b384825
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
65 changes: 65 additions & 0 deletions tests/specs/core/Ajax.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {expect, use, spy} from 'chai';
import * as spies from 'chai-spies';
import 'chai-spies';
import Endpoint from '../../../src/core/Endpoint';
import { variables } from '../global';
import { HttpMethod } from '../../../src/core/types';

use(spies);

describe('test ajax', () => {
let endpoint:Endpoint;
before(() => {
endpoint = new Endpoint(variables.server.host);
endpoint.registerAPI('listUsers', {
path: '/users.do',
method: HttpMethod.GET
})
endpoint.registerAPI('getUser', {
path: '/user/:id.do',
method: HttpMethod.GET,
pathVariables: [{
name: 'id',
required: true
}]
})
endpoint.registerAPI('getRole', {
path: '/role/:id.do',
method: HttpMethod.GET,
pathVariables: [{
name: 'id',
required: true
}]
})
endpoint.registerAPI('listRoles', {
path: '/roles.do',
method: HttpMethod.GET
})
});
it('registered api should not undefined', () => {
expect(endpoint.api('listUsers')).not.undefined
expect(endpoint.api('getUser')).not.undefined
expect(endpoint.api('getRole')).not.undefined
expect(endpoint.api('listRoles')).not.undefined
})
it('should throw when get unregistered api', () => {
expect(() => {
endpoint.api('')
}).throw
})
it('should throw when missing required `pathVariable` parameter', async () => {
const catchSpy = spy(() => {
//
});
try {
await endpoint.api('getUser').request();
} catch (error) {
catchSpy();
const message = `Required parameter 'id' of pathVariables is missing and 'defaultValue' of api config is not defined.`;
expect(error.message).eq(message);
}
expect(catchSpy).to.be.called;
});
})


8 changes: 0 additions & 8 deletions tests/specs/core/Endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,5 @@ describe('test Endpoint', () => {
});
expect(endpoint.api(apiname)).to.not.undefined;
expect(endpoint.api(apiname)).to.not.null;
endpoint
.api(apiname)
.request({
pathVariables: {
id: '0',
},
})
.then(console.log, console.error);
});
});

0 comments on commit b384825

Please sign in to comment.