CartoDB-SQL-API/test/unit/query_info.test.js
2018-05-22 14:16:22 +02:00

64 lines
2.3 KiB
JavaScript

const assert = require('assert');
const queryInfo = require('../../app/utils/query_info');
describe('query info', function () {
describe('copy format', function () {
describe('csv', function () {
const validQueries = [
"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)",
];
validQueries.forEach(query => {
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'CSV');
});
});
});
describe('text', function() {
const validQueries = [
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT TEXT)",
"COPY copy_endpoints_test (id, name) FROM STDIN",
];
validQueries.forEach(query => {
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'TEXT');
});
});
});
describe('binary', function() {
const validQueries = [
"COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT BINARY)",
];
validQueries.forEach(query => {
it(query, function() {
const result = queryInfo.getFormatFromCopyQuery(query);
assert.equal(result, 'BINARY');
});
});
});
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);
});
});
});
});
});