Commit c0b8b938 authored by Rafael Dias's avatar Rafael Dias

Issue #88: Refactor struct of tests

Signed-off-by: Rafael Dias's avatarRafael <rpd17@inf.ufpr.br>
parent ba277989
Pipeline #17827 passed with stages
in 48 seconds
-
name: "dim:2"
dataType: "integer"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:3"
dataType: "string"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:4"
dataType: "string"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:5"
dataType: "boolean"
description: "A dimension of Blendb. Has 2 possible values."
-
name: "dim:6"
dataType: "integer"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:7"
dataType: "integer"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:8"
dataType: "integer"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:9"
dataType: "integer"
parent: "dim:0"
relation: "day"
description: "A dimension of Blendb. Has 30 possible values."
-
name: "dim:10"
dataType: "integer"
parent: "dim:0"
relation: "month"
description: "A dimension of Blendb. Has 12 possible values."
-
name: "dim:11"
dataType: "integer"
parent: "dim:0"
relation: "year"
description: "A dimension of Blendb. Has 1 possible value."
-
name: "enumtype:1"
values:
- "test_4"
- "test_5"
- "test_6"
- "string"
-
name: "enumtype:2"
values:
- "test_7"
- "test_8"
-
name: "enumtype:3"
values:
- "test_9"
-
name: "met:2"
dataType: "integer"
aggregation: "avg"
description: "No meaning, just used for test"
-
name: "met:3"
dataType: "integer"
aggregation: "sum"
description: "No meaning, just used for test"
-
name: "met:4"
dataType: "integer"
aggregation: "sum"
description: "No meaning, just used for test"
-
name: "met:5"
dataType: "integer"
aggregation: "avg"
description: "No meaning, just used for test"
-
name: "met:6"
dataType: "integer"
aggregation: "count"
description: "No meaning, just used for test"
-
name: "met:7"
dataType: "integer"
aggregation: "count"
description: "No meaning, just used for test"
-
name: "met:8"
dataType: "integer"
aggregation: "sum"
description: "No meaning, just used for test"
-
name: "met:9"
dataType: "integer"
aggregation: "count"
description: "No meaning, just used for test"
-
name: "met:10"
dataType: "integer"
aggregation: "max"
description: "No meaning, just used for test"
-
name: "met:11"
dataType: "integer"
aggregation: "min"
description: "No meaning, just used for test"
-
name: "source_1"
description: "source with 2 entries"
fields:
-
name: "fields:0"
description: "first entry"
dataType: "enumtype"
enumType: "enumtype:0"
-
name: "fields:1"
description: "second entry"
dataType: "string"
-
name: "source_2"
description: "source with one entry and undefined dataType"
fields:
-
name: "fields:0"
description: "first entry"
dataType: "string"
-
name: "source_3"
description: "source with one entry and without description"
fields:
-
name: "fields:0"
dataType: "string"
-
name: "source_4"
description: "source with all core types from blendb"
fields:
-
name: "fields:0"
description: "first entry"
dataType: "integer"
-
name: "fields:1"
description: "second entry"
dataType: "float"
-
name: "fields:2"
description: "third entry"
dataType: "string"
-
name: "fields:3"
description: "fourth entry"
dataType: "boolean"
-
name: "fields:4"
description: "fifth entry"
dataType: "date"
......@@ -3,76 +3,71 @@
# so this example file in fact is the CI test file
views:
links:
- config/ci_views.yaml.example
- config/market_views.yaml.example
obj:
-
alias: "View 0"
data: "test/postgres/fixtures/view0.json"
alias: "Seller"
data: "test/postgres/fixtures/seller.json"
origin: true
dimensions:
- "dim:0"
- "dim:7"
- "dim:seller:name"
- "dim:seller:sex"
- "dim:seller:cpf"
- "dim:seller:id"
- "dim:seller:status"
metrics:
- "met:0"
- "met:1"
- "met:2"
- "met:10"
- "met:seller:avg:age"
- "met:seller:max:age"
- "met:seller:min:age"
- "met:seller:count:age"
metrics:
links:
- config/ci_metrics.yaml.example
- config/ci_metrics_1.yaml.example
- config/market_metrics.yaml.example
obj:
-
name: "met:0"
dataType: "integer"
aggregation: "sum"
description: "No meaning, just used for test"
-
name: "met:1"
dataType: "integer"
-
name: "met:seller:avg:age"
dataType: "float"
aggregation: "avg"
description: "No meaning, just used for test"
description: "The seller average age"
dimensions:
links:
- config/ci_dimensions.yaml.example
- config/market_dimensions.yaml.example
obj:
-
name: "dim:0"
dataType: "date"
description: "A dimension of Blendb. Has 5 possible values."
-
name: "dim:1"
dataType: "date"
description: "A dimension of Blendb. Has 5 possible values."
name: "dim:seller:name"
dataType: "string"
description: "Name of the seller from market"
enumTypes:
links:
- config/ci_enumtypes.yaml.example
- config/market_enum.yaml.example
obj:
-
name: "enumtype:0"
values:
- "male"
- "female"
- "binary"
- "undecided"
- []
sources:
links:
- config/ci_sources.yaml.example
- config/market_sources.yaml.example
obj:
-
name: "source_0"
description: "source with 3 entries"
name: "Seller"
description: "Market worker"
fields:
-
name: "fields:0"
description: "first entry"
dataType: "string"
-
name: "fields:1"
description: "second entry"
name: "name"
description: "Seller name"
dataType: "string"
-
name: "fields:2"
description: "third entry"
name: "age"
description: "Seller age"
dataType: "integer"
-
name: "sex"
description: "Seller sex"
enumType: "enumsex"
dataType: "enumtype"
-
name: "CPF"
description: "Seller CPF"
dataType: "string"
-
name: "id"
description: "Seller id"
dataType: "integer"
-
alias: "View 1"
data: "test/postgres/fixtures/view1.json"
origin: true
dimensions:
- "dim:1"
- "dim:8"
metrics:
- "met:3"
- "met:4"
-
alias: "View 2"
data: "test/postgres/fixtures/view2.json"
origin: true
dimensions:
- "dim:2"
metrics:
- "met:5"
- "met:6"
- "met:11"
-
alias: "View 3"
data: "test/postgres/fixtures/view3.json"
origin: true
dimensions:
- "dim:2"
- "dim:3"
- "dim:4"
-
alias: "View 4"
data: "test/postgres/fixtures/view4.json"
origin: true
dimensions:
- "dim:2"
- "dim:7"
- "dim:8"
-
alias: "View 5"
data: "test/postgres/fixtures/view5.json"
origin: true
dimensions:
- "dim:3"
metrics:
- "met:7"
-
alias: "View 6"
data: "test/postgres/fixtures/view6.json"
origin: true
dimensions:
- "dim:4"
metrics:
- "met:8"
-
alias: "View 7"
data: "test/postgres/fixtures/view7.json"
origin: true
dimensions:
- "dim:4"
- "dim:5"
- "dim:6"
-
alias: "View 8"
data: "test/postgres/fixtures/view8.json"
origin: true
dimensions:
- "dim:5"
- "dim:6"
metrics:
- "met:9"
-
alias: "view 9"
data: "test/postgres/fixtures/view9.json"
origin: false
dimensions:
- "dim:2"
metrics:
- "met:5"
- "met:6"
- "met:7"
clauses:
- "dim:2!=1"
-
name: "dim:seller:name"
dataType: "string"
description: "The name of the seller from market"
-
name: "dim:seller:sex"
dataType: "enumtype"
......@@ -8,9 +12,10 @@
dataType: "string"
description: "CPF of the seller from market"
-
name: "dim:seller:id"
dataType: "integer"
description: "id of the seller from market"
name: "dim:seller:status"
dataType: "enumtype"
enumType: "workingStatus"
description: "The status of the seller from market"
-
name: "dim:product:name"
dataType: "string"
......@@ -19,10 +24,6 @@
name: "dim:product:validity"
dataType: "date"
description: "Validity of the product from market"
-
name: "dim:product:id"
dataType: "integer"
description: "id of the product from market"
-
name: "dim:client:name"
dataType: "string"
......@@ -31,24 +32,16 @@
name: "dim:client:cpf"
dataType: "string"
description: "CPF of the client from market"
-
name: "dim:client:id"
dataType: "integer"
description: "id of the client from market"
-
name: "dim:sell:registered"
dataType: "boolean"
description: "Check if the client is registered"
-
name: "dim:sell:product.id"
dataType: "integer"
description: "id of the product from market"
description: "Check if the client is registered"
-
name: "dim:sell:seller.id"
name: "dim:seller:id"
dataType: "integer"
description: "id of the seller from market"
-
name: "dim:sell:client.id"
name: "dim:client:id"
dataType: "integer"
description: "id of the client from market"
-
......@@ -58,28 +51,17 @@
-
name: "dim:buyout:datein"
dataType: "date"
description: "Date of the buyout was realized"
description: "Date of the buyout was realized"
-
name: "dim:buyout:provider.id"
dataType: "integer"
description: "id of the provider from market"
-
name: "dim:buyout:product.id"
name: "dim:product:id"
dataType: "integer"
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: "integer"
description: "id of the provider from market"
-
name: "dim:distribute:provider.id"
dataType: "string"
description: "id of the provider from market"
-
name: "dim:distribute:product.id"
dataType: "string"
description: "id of the product from market"
......@@ -5,4 +5,13 @@
- "female"
- "nonbinary"
- "undecided"
-
name: "workingStatus"
values:
- "active"
- "inactive"
- "vacation"
- "sick leave"
- "maternity leave"
......@@ -4,13 +4,14 @@ views:
obj:
-
alias: "Seller"
data: "test/postgres/fixtures/view10.json"
data: "test/postgres/fixtures/seller.json"
origin: true
dimensions:
- "dim:seller:name"
- "dim:seller:sex"
- "dim:seller:cpf"
- "dim:seller:id"
- "dim:seller:status"
metrics:
- "met:seller:avg:age"
- "met:seller:max:age"
......
-
name: "met:seller:avg:age"
dataType: "float"
aggregation: "avg"
description: "The seller average age"
-
name: "met:seller:max:age"
dataType: "integer"
......
-
alias: "Product"
data: "test/postgres/fixtures/view11.json"
data: "test/postgres/fixtures/product.json"
origin: true
dimensions:
- "dim:product:name"
......@@ -15,7 +15,7 @@
- "met:product:min:priceout"
-
alias: "Client"
data: "test/postgres/fixtures/view12.json"
data: "test/postgres/fixtures/client.json"
origin: true
dimensions:
- "dim:client:name"
......@@ -23,13 +23,13 @@
- "dim:client:id"
-
alias: "Sell"
data: "test/postgres/fixtures/view13.json"
data: "test/postgres/fixtures/sell.json"
origin: true
dimensions:
- "dim:sell:registered"
- "dim:sell:product.id"
- "dim:sell:seller.id"
- "dim:sell:client.id"
- "dim:product:id"
- "dim:seller:id"
- "dim:client:id"
- "dim:sell:datein"
metrics:
- "met:sell:sum:quantity"
......@@ -37,27 +37,38 @@
- "met:sell:count:quantity"
-
alias: "Buyout"
data: "test/postgres/fixtures/view14.json"
data: "test/postgres/fixtures/buyout.json"
origin: true
dimensions:
- "dim:buyout:datein"
- "dim:buyout:provider.id"
- "dim:buyout:product.id"
- "dim:provider:id"
- "dim:product:id"
metrics:
- "met:buyout:avg:quantity"
- "met:buyout:max:quantity"
- "met:buyout:min:quantity"
-
alias: "Provider"
data: "test/postgres/fixtures/view15.json"
data: "test/postgres/fixtures/provider.json"
origin: true
dimensions:
- "dim:provider:name"
- "dim:provider:id"
-
alias: "Distribute"
data: "test/postgres/fixtures/view16.json"
data: "test/postgres/fixtures/distribute.json"
origin: true
dimensions:
- "dim:distribute:provider.id"
- "dim:distribute:product.id"
- "dim:provider:id"
- "dim:product:id"
-
alias: "ActiveSeller"
data: "test/postgres/fixtures/activeseller.json"
origin: true
dimensions:
- "dim:seller:name"
- "dim:seller:status"
metrics:
- "met:seller:max:age"
clauses:
- "dim:seller:status==active"
This diff is collapsed.
This diff is collapsed.
......@@ -99,15 +99,18 @@ export class CollectCtrl {
},
"boolean": function(value: any) {
let test: string = value;
test = test.toLocaleLowerCase();
if (test === "true" || test === "false"){
let test = typeof(value);
if(test === "boolean"){
return true;
}
else{
return false;
}
}else{
let test: string = value;
test = test.toLocaleLowerCase();
if (test === "true" || test === "false"){
return true;
}else{
return false;
}
}
}
};
......@@ -126,7 +129,10 @@ export class CollectCtrl {
for (let i = 0; i < fields.length; i++){
data[i] = req.body[fields[i].name];
if (!data[i]){
// check if the data is empty, however since data may be
// true/false, it must guarantee that it isn't a boolean
// then it'll test if it's empty
if (!(typeof(data[i]) === "boolean") && !data[i]){
throw new Error(
"The '" + fields[i].name + "' wasn't informed on json");
}
......@@ -158,13 +164,7 @@ export class CollectCtrl {
"The value '" + data[i] + "' from '" + fields[i].name +
"' isn't a type " + [EnumHandler.stringfyDataType(fields[i].dataType)]);
}
}
// undefined DataType
else{
throw new Error(
"The value '" + data[i] + "' from '" + fields[i].name +
"' isn't listed on " + fields[i].enumType);
}
}
}
}
......
......@@ -20,7 +20,6 @@
import * as request from "supertest";
import { expect } from "chai";
import * as server from "../../main";
import { dataCtrlScenario as tests } from "../../../test/scenario";
import { Query } from "../../common/query";
......@@ -53,7 +52,8 @@ describe("API data controller", () => {
.expect((res: any) => {
const message = "Query execution failed: " +
"Could not construct query with the given parameters.";
const error = "The metric named met:-1 was not found";
const error = "The metric named met:this:is:just:a:test" +
" was not found";
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message");
expect(res.body).to.have.property("error");
......@@ -71,7 +71,8 @@ describe("API data controller", () => {
.expect((res: any) => {
const message = "Query execution failed: " +
"Could not construct query with the given parameters.";
const error = "The dimension named dim:-1 was not found";
const error = "The dimension named dim:this:is:just:a:test" +
" was not found";
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message");
expect(res.body).to.have.property("error");
......@@ -83,7 +84,7 @@ describe("API data controller", () => {
it("should respond 500 when query has sort item that is not in query data", (done) => {
let query = parseQuery(tests.clausal);
query.sort = "dim:0";
query.sort = "dim:does:not:exist";
request(server)
.get("/v1/data")
.query(query)
......@@ -91,7 +92,7 @@ describe("API data controller", () => {
.expect((res: any) => {
const message = "Query execution failed: " +
"Could not construct query with the given parameters.";
const error = "The item 'dim:0'" +
const error = "The item 'dim:does:not:exist'" +
" is not present in neither metrics nor dimensions list";
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message");
......@@ -124,10 +125,8 @@ describe("API data controller", () => {
});
it("should respond 200 and get some data, using a single filter", (done) => {
// Clause does not come to scenario besause is a lot of work for
// only a single test
let query = parseQuery(tests.clausal);
query.filters = "dim:7==1";
query.filters = "dim:product:name==Bacon";
request(server)
.get("/v1/data")
.query(query)
......@@ -149,10 +148,8 @@ describe("API data controller", () => {
});
it("should respond 200 and get some data, using filters with OR", (done) => {
// Clause does not come to scenario besause is a lot of work for
// only a single test
let query = parseQuery(tests.clausal);
query.filters = "dim:7==1,dim:7==2";
query.filters = "dim:product:name==Trento,dim:product:name==Meat";
request(server)
.get("/v1/data")
.query(query)
......@@ -174,10 +171,8 @@ describe("API data controller", () => {
});
it("should respond 200 and get some data, using filters with AND", (done) => {
// Clause does not come to scenario besause is a lot of work for
// only a single test
let query = parseQuery(tests.clausal);
query.filters = "dim:7!=1;dim:0!=2017-01-01";
query.filters = "dim:product:name!=Bacon;dim:product:validity!=2018-05-10";
request(server)
.get("/v1/data")
.query(query)
......@@ -185,7 +180,7 @@ describe("API data controller", () => {
.expect((res: any) => {
let result = res.body;
expect(result).to.be.an("array");
expect(result).to.have.length(4);
expect(result).to.have.length(3);
expect(result[0]).to.be.an("object");
let keys: string[] = [];
keys = keys.concat(tests.clausal.metrics.map((item) => item.name));
......@@ -199,10 +194,8 @@ describe("API data controller", () => {
});
it("should respond 200 and get some data, sorted", (done) => {
// Clause does not come to scenario besause is a lot of work for
// only a single test
let query = parseQuery(tests.clausal);
query.sort = "dim:7,met:0";
query.sort = "dim:product:id,met:product:avg:pricein";
request(server)
.get("/v1/data")
.query(query)
......@@ -219,7 +212,8 @@ describe("API data controller", () => {
const row = result[i];
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
expect(row["dim:7"]).to.be.eql(i + 1);
// the magic number will be the first dim:product:id
expect(row["dim:product:id"]).to.be.eql(i + 53);