CartoDB-SQL-API/test/unit/query_info.test.js

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-05-22 01:13:44 +08:00
const assert = require('assert');
const queryInfo = require('../../app/utils/query_info');
describe('query info', function () {
2018-05-22 20:16:22 +08:00
describe('copy format', function () {
describe('csv', function () {
2018-05-22 18:05:16 +08:00
const validQueries = [
2018-05-22 01:13:44 +08:00
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)",
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)",
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV , DELIMITER ',', HEADER true)",
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV)",
2018-06-05 00:15:28 +08:00
"COPY copy_endpoints_test FROM STDIN WITH(FORMAT csv,HEADER true)"
2018-05-22 01:13:44 +08:00
];
2018-05-22 18:05:16 +08:00
validQueries.forEach(query => {
2018-05-22 01:13:44 +08:00
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'CSV');
});
});
});
describe('text', function() {
2018-05-22 18:05:16 +08:00
const validQueries = [
2018-05-22 01:13:44 +08:00
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT TEXT)",
"COPY copy_endpoints_test (id, name) FROM STDIN",
];
2018-05-22 18:05:16 +08:00
validQueries.forEach(query => {
2018-05-22 01:13:44 +08:00
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'TEXT');
});
});
});
2018-05-22 18:05:16 +08:00
describe('binary', function() {
const validQueries = [
2018-05-22 01:13:44 +08:00
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT BINARY)",
];
2018-05-22 18:05:16 +08:00
validQueries.forEach(query => {
2018-05-22 01:13:44 +08:00
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'BINARY');
});
});
});
2018-05-22 20:16:22 +08:00
describe('should fail', function() {
const validQueries = [
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT ERROR)",
"SELECT * from copy_endpoints_test"
];
validQueries.forEach(query => {
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.strictEqual(result, false);
});
});
});
2018-05-22 01:13:44 +08:00
});
});