mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
Feat: jambonz Client (#185)
* feat: client schema change * feat: add testcases * fix typo * hash client password * fix fk * upgrade script * fix failing testcase
This commit is contained in:
117
test/clients.js
Normal file
117
test/clients.js
Normal file
@@ -0,0 +1,117 @@
|
||||
const test = require('tape') ;
|
||||
const ADMIN_TOKEN = '38700987-c7a4-4685-a5bb-af378f9734de';
|
||||
const authAdmin = {bearer: ADMIN_TOKEN};
|
||||
const request = require('request-promise-native').defaults({
|
||||
baseUrl: 'http://127.0.0.1:3000/v1'
|
||||
});
|
||||
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||
});
|
||||
|
||||
test('client test', async(t) => {
|
||||
const app = require('../app');
|
||||
|
||||
try {
|
||||
let result;
|
||||
/* add a service provider */
|
||||
result = await request.post('/ServiceProviders', {
|
||||
resolveWithFullResponse: true,
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
body: {
|
||||
name: 'client_sp',
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created client service provider');
|
||||
const sp_sid = result.body.sid;
|
||||
|
||||
/* add an account */
|
||||
result = await request.post('/Accounts', {
|
||||
resolveWithFullResponse: true,
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
body: {
|
||||
name: 'sample_account',
|
||||
service_provider_sid: sp_sid,
|
||||
registration_hook: {
|
||||
url: 'http://example.com/reg',
|
||||
method: 'get'
|
||||
},
|
||||
webhook_secret: 'foobar'
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created account');
|
||||
const account_sid = result.body.sid;
|
||||
|
||||
/* add new entity */
|
||||
result = await request.post('/Clients', {
|
||||
resolveWithFullResponse: true,
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
body: {
|
||||
account_sid,
|
||||
username: 'client1',
|
||||
password: 'sdf12412',
|
||||
is_active: 1
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 201, 'successfully created Client');
|
||||
const sid = result.body.sid;
|
||||
|
||||
/* query all entity */
|
||||
result = await request.get('/Clients', {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.length === 1 , 'successfully queried all Clients');
|
||||
|
||||
/* query one entity */
|
||||
result = await request.get(`/Clients/${sid}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.account_sid === account_sid , 'successfully retrieved Client by sid');
|
||||
t.ok(result.client_sid, 'successfully retrieved Client by sid');
|
||||
t.ok(result.username === 'client1', 'successfully retrieved Client by sid');
|
||||
t.ok(result.is_active === 1 , 'successfully retrieved Client by sid');
|
||||
|
||||
/* update the entity */
|
||||
result = await request.put(`/Clients/${sid}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
body: {
|
||||
is_active: 0
|
||||
}
|
||||
});
|
||||
t.ok(result.statusCode === 204, 'successfully updated Client');
|
||||
/* query one entity */
|
||||
result = await request.get(`/Clients/${sid}`, {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.is_active === 0 , 'successfully updated Client');
|
||||
|
||||
/* delete Client */
|
||||
result = await request.delete(`/Clients/${sid}`, {
|
||||
resolveWithFullResponse: true,
|
||||
simple: false,
|
||||
json: true,
|
||||
auth: authAdmin
|
||||
});
|
||||
t.ok(result.statusCode === 204, 'successfully deleted Clients');
|
||||
|
||||
/* query all entity */
|
||||
result = await request.get('/Clients', {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
t.ok(result.length === 0 , 'successfully queried all Clients');
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
})
|
||||
@@ -24,4 +24,5 @@ require('./lcr-carriers-set-entries');
|
||||
require('./lcr-routes');
|
||||
require('./lcrs');
|
||||
require('./tts-cache');
|
||||
require('./clients');
|
||||
require('./docker_stop');
|
||||
|
||||
Reference in New Issue
Block a user