Added tests for GET /domains
This commit is contained in:
parent
f76a0ed8a8
commit
b38cf25a75
5 changed files with 123 additions and 7 deletions
|
@ -3,10 +3,11 @@
|
|||
-- http://www.phpmyadmin.net
|
||||
--
|
||||
-- Host: localhost
|
||||
-- Generation Time: Mar 23, 2018 at 02:29 PM
|
||||
-- Generation Time: Mar 24, 2018 at 01:13 PM
|
||||
-- Server version: 5.7.21-0ubuntu0.16.04.1
|
||||
-- PHP Version: 7.0.28-0ubuntu0.16.04.1
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
@ -16,7 +17,6 @@ SET time_zone = "+00:00";
|
|||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
|
@ -86,7 +86,10 @@ CREATE TABLE `domains` (
|
|||
|
||||
INSERT INTO `domains` (`id`, `name`, `master`, `last_check`, `type`, `notified_serial`, `account`) VALUES
|
||||
(1, 'example.com', NULL, NULL, 'MASTER', NULL, NULL),
|
||||
(2, 'slave.example.net', '12.34.56.78', NULL, 'SLAVE', NULL, NULL);
|
||||
(2, 'slave.example.net', '12.34.56.78', NULL, 'SLAVE', NULL, NULL),
|
||||
(3, 'foo.de', NULL, NULL, 'NATIVE', NULL, NULL),
|
||||
(4, 'bar.net', NULL, NULL, 'MASTER', NULL, NULL),
|
||||
(5, 'baz.org', NULL, NULL, 'MASTER', NULL, NULL);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -267,7 +270,7 @@ ALTER TABLE `domainmetadata`
|
|||
-- AUTO_INCREMENT for table `domains`
|
||||
--
|
||||
ALTER TABLE `domains`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
|
||||
--
|
||||
-- AUTO_INCREMENT for table `records`
|
||||
--
|
||||
|
@ -282,7 +285,8 @@ ALTER TABLE `tsigkeys`
|
|||
-- AUTO_INCREMENT for table `users`
|
||||
--
|
||||
ALTER TABLE `users`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;SET FOREIGN_KEY_CHECKS=1;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
|
|
5
backend/test/package-lock.json
generated
5
backend/test/package-lock.json
generated
|
@ -13,6 +13,11 @@
|
|||
"is-buffer": "1.1.6"
|
||||
}
|
||||
},
|
||||
"cartesian-product": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/cartesian-product/-/cartesian-product-2.1.2.tgz",
|
||||
"integrity": "sha1-yahGLFSrGaDF/TIZKSLiOatMpP0="
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "Dependencies for pdnsmanager test",
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0"
|
||||
"axios": "^0.18.0",
|
||||
"cartesian-product": "^2.1.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ then
|
|||
clearConfig
|
||||
exit 1
|
||||
else
|
||||
if [ $(wc -l logfile.log) -gt 0 ]
|
||||
if [ $(cat logfile.log | wc -l) -gt 0 ]
|
||||
then
|
||||
echo "Errors in logfile:"
|
||||
cat "logfile.log"
|
||||
|
|
106
backend/test/tests/domains-get.js
Normal file
106
backend/test/tests/domains-get.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
const cartesianProduct = require('cartesian-product');
|
||||
|
||||
require('../testlib')(async function (assert, req) {
|
||||
//GET /domains?page=5&pagesize=10&query=foo&sort=id-asc,name-desc,type-asc,records-asc&type=MASTER
|
||||
|
||||
//Test sorting in all combinations
|
||||
const sortCombinations = cartesianProduct([
|
||||
['', 'id-asc', 'id-desc'],
|
||||
['', 'name-asc', 'name-desc'],
|
||||
['', 'type-asc', 'type-desc'],
|
||||
['', 'records-asc', 'records-desc']
|
||||
]);
|
||||
|
||||
for (list of sortCombinations) {
|
||||
list = list.filter((str) => str.length > 0);
|
||||
var sortQuery = list.join(',');
|
||||
|
||||
var res = await req({
|
||||
url: '/domains?sort=' + sortQuery,
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
|
||||
var sortedData = res.data.results.slice();
|
||||
sortedData.sort(function (a, b) {
|
||||
for (sort of list) {
|
||||
var spec = sort.split('-');
|
||||
if (a[spec[0]] < b[spec[0]]) {
|
||||
return spec[1] == 'asc' ? -1 : 1;
|
||||
} else if (a[spec[0]] > b[spec[0]]) {
|
||||
return spec[1] == 'asc' ? 1 : -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
assert.equal(res.data.results, sortedData, 'Sort failed for ' + res.config.url);
|
||||
}
|
||||
|
||||
//Test paging
|
||||
var res = await req({
|
||||
url: '/domains?pagesize=3',
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
assert.equal(res.status, 200, 'Status should be OK');
|
||||
assert.equal(res.data.paging, {
|
||||
page: 1,
|
||||
total: 2,
|
||||
pagesize: 3
|
||||
}, 'Paging data fail for ' + res.config.url);
|
||||
assert.equal(res.data.results.length, 3, "Should be 3 results.");
|
||||
|
||||
var res = await req({
|
||||
url: '/domains?pagesize=3&page=2',
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
assert.equal(res.status, 200, 'Status should be OK');
|
||||
assert.equal(res.data.paging, {
|
||||
page: 2,
|
||||
total: 2,
|
||||
pagesize: 3
|
||||
}, 'Paging data fail for ' + res.config.url);
|
||||
assert.equal(res.data.results.length, 2, "Should be 2 results.");
|
||||
|
||||
//Test query
|
||||
var res = await req({
|
||||
url: '/domains?query=.net&sort=id-asc',
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
assert.equal(res.status, 200, 'Status should be OK');
|
||||
assert.equal(res.data.results, [
|
||||
{
|
||||
id: '2',
|
||||
name: 'slave.example.net',
|
||||
type: 'SLAVE',
|
||||
master: '12.34.56.78',
|
||||
records: '0'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
name: 'bar.net',
|
||||
type: 'MASTER',
|
||||
records: '0'
|
||||
}
|
||||
], 'Result fail for ' + res.config.url);
|
||||
|
||||
//Type filter
|
||||
var res = await req({
|
||||
url: '/domains?type=NATIVE',
|
||||
method: 'get'
|
||||
});
|
||||
|
||||
assert.equal(res.status, 200, 'Status should be OK');
|
||||
assert.equal(res.data.results, [
|
||||
{
|
||||
id: '3',
|
||||
name: 'foo.de',
|
||||
type: 'NATIVE',
|
||||
records: '0'
|
||||
}
|
||||
], 'Result fail for ' + res.config.url);
|
||||
});
|
Loading…
Reference in a new issue