Commit 3b0a5eec authored by rafaelatc3sl's avatar rafaelatc3sl

Issue #92: Improve test coverage

Signed-off-by: 's avatarrafaelatc3sl <rpd17@c3sl>
parent 72c00bdc
Pipeline #18958 passed with stages
in 1 minute and 7 seconds
......@@ -24,22 +24,11 @@ stages:
- deploy
run_test_postgres:
run_test:
stage: test
script:
- yarn install --frozen-lockfile --silent --non-interactive
- mv config/ci_postgres_test.env.example config/test.env
- yarn test
- yarn run lint
tags:
- node
- postgres
run_test_monet:
stage: test
script:
- yarn install --frozen-lockfile --silent --non-interactive
- mv config/ci_monet_test.env.example config/test.env
- mv config/ci_database_test.env.example config/test.env
- yarn test
- yarn run lint
tags:
......
PORT=3000
BLENDB_N_DB=2
BLENDB_DB0_USER=runner
BLENDB_DB0_NAME=blendb_fixture
BLENDB_DB0_PASSWORD=
BLENDB_DB0_HOST=postgres
BLENDB_DB0_PORT=5432
BLENDB_DB0_ADAPTER=postgres
BLENDB_DB1_USER=monetdb
BLENDB_DB1_NAME=blendb_fixture
BLENDB_DB1_PASSWORD=monetdb
BLENDB_DB1_HOST=monet
BLENDB_DB1_PORT=50000
BLENDB_DB1_ADAPTER=monet
BLENDB_SCHEMA_FILE=config/ci_test.yaml.example
BLENDB_DB_USER=monetdb
BLENDB_DB_NAME=blendb_fixture
BLENDB_DB_PASSWORD=monetdb
BLENDB_DB_HOST=monet
BLENDB_DB_PORT=50000
BLENDB_ADAPTER=monet
BLENDB_SCHEMA_FILE=config/ci_test.yaml.example
PORT=3000
BLENDB_DB_USER=runner
BLENDB_DB_NAME=blendb_fixture
BLENDB_DB_PASSWORD=
BLENDB_DB_HOST=postgres
BLENDB_DB_PORT=5432
BLENDB_ADAPTER=postgres
BLENDB_SCHEMA_FILE=config/ci_test.yaml.example
PORT=3000
......@@ -46,6 +46,7 @@ enumTypes:
sources:
links:
- config/market_sources.yaml.example
- config/source_test_only.yaml.example
obj:
-
name: "Seller"
......
......@@ -19,27 +19,27 @@
-
name: "dim:product:name"
dataType: "string"
description: "Name of the product from market"
description: "Name of the product from market"
-
name: "dim:product:validity"
dataType: "date"
description: "Validity of the product from market"
-
-
name: "dim:client:name"
dataType: "string"
description: "Name of the client from market"
-
-
name: "dim:client:cpf"
dataType: "string"
description: "CPF of the client from market"
-
name: "dim:sell:registered"
dataType: "boolean"
description: "Check if the client is registered"
description: "Check if the client is registered"
-
name: "dim:seller:id"
dataType: "integer"
description: "id of the seller from market"
description: "id of the seller from market"
-
name: "dim:client:id"
dataType: "integer"
......@@ -47,21 +47,39 @@
-
name: "dim:sell:datein"
dataType: "date"
description: "Date of the sell was realized"
description: "Date of the sell was realized"
-
name: "dim:buyout:datein"
dataType: "date"
description: "Date of the buyout was realized"
description: "Date of the buyout was realized"
-
name: "dim:product:id"
dataType: "integer"
description: "id of the product from market"
description: "id of the product from market"
-
name: "dim:provider:name"
dataType: "string"
description: "Name of the provider from market"
description: "Name of the provider from market"
-
name: "dim:provider:id"
dataType: "string"
description: "id of the provider from market"
description: "id of the provider from market"
-
name: "dim:buyout:day"
dataType: "integer"
parent: "dim:buyout:datein"
relation: "day"
description: "Date of the buyout was realized"
-
name: "dim:buyout:month"
dataType: "integer"
parent: "dim:buyout:datein"
relation: "month"
description: "Date of the buyout was realized"
-
name: "dim:buyout:year"
dataType: "integer"
parent: "dim:buyout:datein"
relation: year
description: "Date of the buyout was realized"
......@@ -13,5 +13,4 @@
- "vacation"
- "sick leave"
- "maternity leave"
- "stand by"
......@@ -79,3 +79,12 @@
- "met:seller:max:age"
clauses:
- "dim:seller:status==active"
-
alias: "view:SellerStatus"
data: "test/postgres/fixtures/sellerstatus.json"
origin: false
aliasAsName: true
metrics:
- "met:seller:count:age"
dimensions:
- "dim:seller:status"
-
name: "test"
description:
fields:
-
name: "noDescriptionString"
description:
dataType: "string"
[
{"met:seller:count:age" : 4, "dim:seller:status" : "active"},
{"met:seller:count:age" : 1, "dim:seller:status" : "sick leave"}
]
......@@ -142,14 +142,6 @@ export class MonetAdapter extends SQLAdapter {
pool.close();
}
/**
* Materialize a given view.
* @param view - View to be materialized.
*/
public materializeView(view: View): boolean {
return false;
}
/**
* Asynchronously insert one register into a given Source.
* @param source - Insertion "location".
......
......@@ -25,246 +25,274 @@ import { Adapter } from "../core/adapter";
import { Fixture as FixPostgres } from "../../test/postgres/fixture";
import { Fixture as FixMonet } from "../../test/monet/fixture";
import { adapterScenario } from "../../test/scenario";
import { eachOf } from "async";
describe("Sql adapter", () => {
let adapters: Adapter[] = [];
let fixture;
function loadDb(db: string, index: number, cb: (err: any, result: Adapter) => void): void {
let adapter: Adapter;
let fixture;
before(function (done): void {
if (adapterScenario.config.adapter === "postgres") {
fixture = new FixPostgres(adapterScenario.config.connection);
fixture.load(adapterScenario.config.loadViews, (err) => {
if (err) {
throw err;
if (db === "postgres") {
fixture = new FixPostgres(adapterScenario.config.connections[index]);
fixture.load(adapterScenario.config.loadViews, (err) => {
if (err) {
throw err;
}
adapter = new PostgresAdapter(adapterScenario.config.connections[index]);
cb(null, adapter);
});
}
else if (db === "monet") {
fixture = new FixMonet(adapterScenario.config.connections[index]);
fixture.load(adapterScenario.config.loadViews, (err) => {
if (err) {
throw err;
}
let parsedConfig: MonetConfig = {
user: adapterScenario.config.connections[index].user,
dbname: adapterScenario.config.connections[index].database,
password: adapterScenario.config.connections[index].password,
host: adapterScenario.config.connections[index].host,
port: adapterScenario.config.connections[index].port
};
adapter = new MonetAdapter(parsedConfig);
cb(null, adapter);
});
}
else{
cb("invalid adapter", null);
}
}
describe("Sql adapter", () => {
// Initializing
before(function (done): void {
// Arrow function not used to get acces to this and skip the test
eachOf(adapterScenario.config.adapters , function(database, key: number, callback) {
loadDb(database, key, function(err, result ) {
if (err){
return callback(err);
}
adapter = new PostgresAdapter(adapterScenario.config.connection);
done();
});
}
else if (adapterScenario.config.adapter === "monet") {
fixture = new FixMonet(adapterScenario.config.connection);
fixture.load(adapterScenario.config.loadViews, (err) => {
if (err) {
throw err;
else{
adapters[key] = result;
}
let parsedConfig: MonetConfig = {
user: adapterScenario.config.connection.user,
dbname: adapterScenario.config.connection.database,
password: adapterScenario.config.connection.password,
host: adapterScenario.config.connection.host,
port: adapterScenario.config.connection.port
};
adapter = new MonetAdapter(parsedConfig);
done();
callback();
});
}
else {
this.skip();
}
}, function (err){
if (err){
this.skip();
}
else{
done();
}
});
});
// Tests
it("should get data from single materialized view", (done) => {
let view = adapterScenario.materializedView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
for (let i = 0; i < adapterScenario.config.ndb; i++ ){
it(adapterScenario.config.adapters[i] + ": " + "should get data from single materialized view", (done) => {
let view = adapterScenario.materializedView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should sort data from join of two views", (done) => {
let view = adapterScenario.sortView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(4);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should sort data from join of two views", (done) => {
let view = adapterScenario.sortView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(4);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from single view (with sub-dimension)", (done) => {
let view = adapterScenario.subDimensionView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
it(adapterScenario.config.adapters[i] + ": " + "should get data from single view (with sub-dimension)", (done) => {
let view = adapterScenario.subDimensionView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from join of one view", (done) => {
let view = adapterScenario.joinWithOneView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from join of one view", (done) => {
let view = adapterScenario.joinWithOneView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from view with a single clause", (done) => {
let view = adapterScenario.filterWithEqual;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(1);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from view with a single clause", (done) => {
let view = adapterScenario.filterWithEqual;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(1);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from reduce with the same attributes of view", (done) => {
let view = adapterScenario.reduceAsView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from reduce with the same attributes of view", (done) => {
let view = adapterScenario.reduceAsView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from join into reduce with a single clause", (done) => {
let view = adapterScenario.filterAverageBought;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(3);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from join into reduce with a single clause", (done) => {
let view = adapterScenario.filterAverageBought;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(3);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from view with multiple clauses", (done) => {
let view = adapterScenario.multipleClause;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(1);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from view with multiple clauses", (done) => {
let view = adapterScenario.multipleClause;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(1);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from view with single clause, with more than one filter", (done) => {
let view = adapterScenario.singleClause;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(4);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from view with single clause, with more than one filter", (done) => {
let view = adapterScenario.singleClause;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(4);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from view with no metrics", (done) => {
let view = adapterScenario.joinWithNoMetrics;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from view with no metrics", (done) => {
let view = adapterScenario.joinWithNoMetrics;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from join with one metric and one view", (done) => {
let view = adapterScenario.growOneView;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from join with one metric and one view", (done) => {
let view = adapterScenario.growOneView;
adapters[i].getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
});
done();
});
done();
});
});
it("should get data from join with unrelated dimension", (done) => {
let view = adapterScenario.JoinWithAncestors;
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(5);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(view.metrics.map((item) => item.name));
keys = keys.concat(view.dimensions.map((item) => item.name));
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
it(adapterScenario.config.adapters[i] + ": " + "should get data from join with unrelated dimension", (done) => {
let view = adapterScenario.JoinWithAncestors;