Fixed bug where numbers where returned as string

This commit is contained in:
Lukas Metzger 2018-03-24 15:09:33 +01:00
parent 5928203a0a
commit 6ec9c81c32
4 changed files with 241 additions and 229 deletions

View file

@ -103,6 +103,8 @@ class Domains
if ($item['type'] != 'SLAVE') {
unset($item['master']);
}
$item['id'] = intval($item['id']);
$item['records'] = intval($item['records']);
return $item;
}, $data);
}
@ -147,6 +149,7 @@ class Domains
$query->execute();
$record = $query->fetch();
$record['id'] = intval($record['id']);
if ($type !== 'SLAVE') {
unset($record['master']);
}

View file

@ -1,6 +1,7 @@
const cartesianProduct = require('cartesian-product');
require('../testlib')('admin', async function (assert, req) {
(async function () {
await require('../testlib')('admin', async function (assert, req) {
//Test missing fields
var res = await req({
url: '/domains',
@ -46,7 +47,7 @@ require('../testlib')('admin', async function (assert, req) {
assert.equal(res.status, 201, 'Creation should be successfull');
assert.equal(res.data, {
id: '6',
id: 6,
name: 'master.de',
type: 'MASTER'
}, 'Creation result fail.')
@ -63,7 +64,7 @@ require('../testlib')('admin', async function (assert, req) {
assert.equal(res.status, 201, 'Creation should be successfull');
assert.equal(res.data, {
id: '7',
id: 7,
name: 'native.de',
type: 'NATIVE'
}, 'Creation result fail.')
@ -74,19 +75,21 @@ require('../testlib')('admin', async function (assert, req) {
method: 'post',
data: {
name: 'slave.de',
type: 'SLAVE'
type: 'SLAVE',
master: '1.2.3.4'
}
});
assert.equal(res.status, 201, 'Creation should be successfull');
assert.equal(res.data, {
id: '8',
id: 8,
name: 'slave.de',
type: 'SLAVE'
type: 'SLAVE',
master: '1.2.3.4'
}, 'Creation result fail.')
});
require('../testlib')('user', async function (assert, req) {
await require('../testlib')('user', async function (assert, req) {
//Test insufficient privileges
var res = await req({
url: '/domains',
@ -98,3 +101,5 @@ require('../testlib')('user', async function (assert, req) {
assert.equal(res.status, 403, 'Domain creation should be forbidden for users.')
});
})();

View file

@ -1,5 +1,6 @@
const cartesianProduct = require('cartesian-product');
(async function () {
require('../testlib')('admin', async function (assert, req) {
//GET /domains?page=5&pagesize=10&query=foo&sort=id-asc,name-desc,type-asc,records-asc&type=MASTER
@ -74,17 +75,17 @@ require('../testlib')('admin', async function (assert, req) {
assert.equal(res.status, 200, 'Status should be OK');
assert.equal(res.data.results, [
{
id: '2',
id: 2,
name: 'slave.example.net',
type: 'SLAVE',
master: '12.34.56.78',
records: '0'
records: 0
},
{
id: '4',
id: 4,
name: 'bar.net',
type: 'MASTER',
records: '0'
records: 0
}
], 'Result fail for ' + res.config.url);
@ -97,10 +98,11 @@ require('../testlib')('admin', async function (assert, req) {
assert.equal(res.status, 200, 'Status should be OK');
assert.equal(res.data.results, [
{
id: '3',
id: 3,
name: 'foo.de',
type: 'NATIVE',
records: '0'
records: 0
}
], 'Result fail for ' + res.config.url);
});
})();

View file

@ -1,4 +1,5 @@
(async function () {
require('../testlib')('admin', async function (assert, req) {
//Try to login with invalid username and password
var res = await req({
@ -59,3 +60,4 @@ require('../testlib')('admin', async function (assert, req) {
assert.equal(res.status, 201, 'Status not valid');
});
})();