Issue #19: Refactor test cases

Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent 5ce681e3
Pipeline #10434 passed with stage
in 2 minutes and 4 seconds
......@@ -14,99 +14,85 @@ struct:
insert: true
schema:
views:
-
alias: "View 0"
data: "test/postgres/fixtures/view0.json"
dimensions:
- "dim:0"
- "dim:7"
metrics:
- "met:0"
- "met:1"
- "met:2"
-
alias: "View 1"
data: "test/postgres/fixtures/view1.json"
dimensions:
- "dim:1"
- "dim:2"
- "dim:8"
metrics:
- "met:1"
- "met:2"
- "met:3"
- "met:4"
-
alias: "View 2"
data: "test/postgres/fixtures/view2.json"
dimensions:
- "dim:1"
- "dim:2"
metrics:
- "met:1"
- "met:3"
- "met:5"
- "met:6"
-
alias: "View 3"
data: "test/postgres/fixtures/view3.json"
dimensions:
- "dim:2"
- "dim:3"
- "dim:4"
- "dim:5"
metrics:
- "met:3"
- "met:4"
- "met:7"
-
alias: "View 4"
data: "test/postgres/fixtures/view4.json"
dimensions:
- "dim:3"
- "dim:4"
- "dim:5"
- "dim:6"
metrics:
- "met:6"
- "met:7"
- "dim:2"
- "dim:7"
- "dim:8"
-
alias: "View 5"
data: "test/postgres/fixtures/view5.json"
dimensions:
- "dim:1"
- "dim:2"
- "dim:7"
- "dim:3"
metrics:
- "met:2"
- "met:3"
- "met:8"
- "met:7"
-
alias: "View 6"
data: "test/postgres/fixtures/view6.json"
dimensions:
- "dim:1"
- "dim:2"
- "dim:4"
metrics:
- "met:1"
- "met:4"
- "met:8"
-
alias: "View 7"
data: "test/postgres/fixtures/view7.json"
dimensions:
- "dim:8"
- "dim:9"
- "dim:10"
metrics:
- "met:8"
- "dim:4"
- "dim:5"
- "dim:6"
-
alias: "View 8"
data: "test/postgres/fixtures/view8.json"
dimensions:
- "dim:8"
- "dim:9"
- "dim:10"
- "dim:5"
- "dim:6"
metrics:
- "met:9"
-
alias: "View 9"
data: "test/postgres/fixtures/view9.json"
dimensions:
- "dim:8"
- "dim:9"
- "dim:10"
metrics:
- "met:10"
metrics:
-
name: "met:1"
name: "met:0"
dataType: "integer"
aggregation: "sum"
-
name: "met:1"
dataType: "integer"
aggregation: "avg"
-
name: "met:2"
dataType: "integer"
......@@ -114,7 +100,7 @@ schema:
-
name: "met:3"
dataType: "integer"
aggregation: "avg"
aggregation: "sum"
-
name: "met:4"
dataType: "integer"
......@@ -122,11 +108,11 @@ schema:
-
name: "met:5"
dataType: "integer"
aggregation: "sum"
aggregation: "avg"
-
name: "met:6"
dataType: "integer"
aggregation: "avg"
aggregation: "count"
-
name: "met:7"
dataType: "integer"
......@@ -134,43 +120,36 @@ schema:
-
name: "met:8"
dataType: "integer"
aggregation: "count"
-
name: "met:9"
dataType: "integer"
aggregation: "sum"
-
name: "met:10"
name: "met:9"
dataType: "integer"
aggregation: "count"
dimensions:
-
name: "dim:0"
dataType: "date"
-
name: "dim:1"
dataType: "date"
-
name: "dim:2"
dataType: "date"
dataType: "integer"
-
name: "dim:3"
dataType: "integer"
dataType: "string"
-
name: "dim:4"
dataType: "string"
-
name: "dim:5"
dataType: "string"
dataType: "boolean"
-
name: "dim:6"
dataType: "boolean"
dataType: "integer"
-
name: "dim:7"
dataType: "integer"
-
name: "dim:8"
dataType: "integer"
-
name: "dim:9"
dataType: "date"
-
name: "dim:10"
dataType: "string"
......@@ -23,13 +23,13 @@
"@types/express": "^4.0.33",
"@types/js-yaml": "^3.5.29",
"@types/pg": "^6.1.38",
"async": "^2.3.0",
"async": "=2.4.1",
"express": "^4.0.33",
"js-yaml": "^3.8.2",
"osprey": "^0.3.2",
"pg": "^6.1.5",
"ts-node": "^1.3.0",
"typescript": "^2.0.3"
"ts-node": "^3.1.0",
"typescript": "^2.4.1"
},
"devDependencies": {
"@types/mocha": "^2.2.32",
......
......@@ -100,7 +100,7 @@ describe("postgres adapter", () => {
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(25);
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));
......@@ -117,7 +117,7 @@ describe("postgres adapter", () => {
adapter.getDataFromView(view, (err, result) => {
expect(err).to.be.a("null");
expect(result).to.be.an("array");
expect(result).to.have.length(125);
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));
......@@ -143,7 +143,7 @@ describe("postgres adapter", () => {
result.forEach((row) => {
expect(row).to.be.an("object");
expect(row).to.have.all.keys(keys);
expect(row).to.have.property("dim:2:year", 2017);
expect(row).to.have.property("dim:0:year", 2017);
});
done();
});
......
......@@ -44,10 +44,10 @@ describe("engine class", () => {
views.forEach((view) => engine.addView(view));
it("should be create a fill that cover the query and has 4 children", () => {
it("should be create a fill that cover all metrics and dimensions", () => {
let query = {
metrics : met.slice(0, 10)
, dimensions : dim.slice(0, 10)
metrics : met
, dimensions : dim
};
let optimalView = engine.query(query);
expect(optimalView).to.be.an("object");
......@@ -58,8 +58,7 @@ describe("engine class", () => {
expect(optimalView.dimensions).to.be.an("array");
expect(optimalView.childViews).to.be.an("array");
expect(optimalView.metrics).to.have.length(10);
expect(optimalView.dimensions).to.have.length(10);
expect(optimalView.childViews).to.have.length(4);
expect(optimalView.dimensions).to.have.length(9);
let metAux: number[] = optimalView.metrics.sort().map((item: Metric) => {
return Number(item.name.split(":")[1]);
});
......@@ -67,15 +66,16 @@ describe("engine class", () => {
return Number(item.name.split(":")[1]);
});
for (let i: number = 0; i < 10; ++i) {
expect(dimAux[i]).to.be.equal(i + 1);
expect(metAux[i]).to.be.equal(i + 1);
for (let i: number = 0; i < 9; ++i) {
expect(dimAux[i]).to.be.equal(i);
expect(metAux[i]).to.be.equal(i);
}
expect(metAux[9]).to.be.equal(9);
});
it("should throw an exception, query with non-existent metric", () => {
let error: boolean = false;
try {
engine.query({metrics: [met[10]], dimensions: [dim[0]]});
engine.query({metrics: [engineScenario.wrongMet], dimensions: [dim[0]]});
}
catch (e){
error = true;
......@@ -88,7 +88,7 @@ describe("engine class", () => {
it("should throw an exception, query with non-existent dimension", () => {
let error: boolean = false;
try {
engine.query({metrics: [met[0]], dimensions: [dim[10]]});
engine.query({metrics: [met[0]], dimensions: [engineScenario.wrongDim]});
}
catch (e){
error = true;
......@@ -100,8 +100,8 @@ describe("engine class", () => {
it("should be create a fill that cover the query, that match perfectly with a existent view", () => {
let query = {
metrics : met.slice(0, 3)
, dimensions : dim.slice(0, 2)
metrics : [met[0], met[1], met[2]]
, dimensions : [dim[0], dim[7]]
};
let optimalView = engine.query(query);
expect(optimalView).to.be.an("object");
......@@ -173,7 +173,7 @@ describe("engine class", () => {
it("should throw an exception, sub-dimension with non-existent parent", () => {
let error: boolean = false;
try {
engine.query({metrics: [met[10]], dimensions: [subdim[3]]});
engine.query({metrics: [met[0]], dimensions: [subdim[3]]});
}
catch (e){
error = true;
......
......@@ -75,11 +75,11 @@ export class Fixture {
To garantee that tables exists before start insert data, series
is used. Inside series each query is executed, using each;
*/
series([(callback) => {
series([(callback: (err: Error) => void) => {
each(init, (query, cback) => {
return client.query(query, [], (err: Error) => cback(err));
}, (errQuery: Error) => callback(errQuery));
}, (callback) => {
}, (callback: (err: Error) => void) => {
each(data, (query, cback) => {
return client.query(query, [], (err: Error) => cback(err));
}, (errQuery: Error) => callback(errQuery));
......
[
{"dim:0":"2017-01-01","dim:7":"1","met:0":"1","met:1":"1","met:2":"1"},
{"dim:0":"2017-01-02","dim:7":"2","met:0":"2","met:1":"2","met:2":"2"},
{"dim:0":"2017-01-03","dim:7":"3","met:0":"3","met:1":"3","met:2":"3"},
{"dim:0":"2017-01-04","dim:7":"4","met:0":"4","met:1":"4","met:2":"4"},
{"dim:0":"2017-01-05","dim:7":"5","met:0":"5","met:1":"5","met:2":"5"}
]
[
{"dim:1":"2017-01-01","dim:2":"2017-01-01","met:1":"1","met:2":"1","met:3":"1"},
{"dim:1":"2017-01-02","dim:2":"2017-01-02","met:1":"2","met:2":"2","met:3":"2"},
{"dim:1":"2017-01-03","dim:2":"2017-01-03","met:1":"3","met:2":"3","met:3":"3"},
{"dim:1":"2017-01-04","dim:2":"2017-01-04","met:1":"4","met:2":"4","met:3":"4"},
{"dim:1":"2017-01-05","dim:2":"2017-01-05","met:1":"5","met:2":"5","met:3":"5"}
{"dim:1":"2017-01-01","dim:8":"1","met:3":"1","met:4":"1"},
{"dim:1":"2017-01-02","dim:8":"2","met:3":"2","met:4":"2"},
{"dim:1":"2017-01-03","dim:8":"3","met:3":"3","met:4":"3"},
{"dim:1":"2017-01-04","dim:8":"4","met:3":"4","met:4":"4"},
{"dim:1":"2017-01-05","dim:8":"5","met:3":"5","met:4":"5"}
]
[
{"dim:1":"2017-01-01","dim:2":"2017-01-01","met:1":"1","met:3":"1","met:5":"1"},
{"dim:1":"2017-01-02","dim:2":"2017-01-02","met:1":"2","met:3":"2","met:5":"2"},
{"dim:1":"2017-01-03","dim:2":"2017-01-03","met:1":"3","met:3":"3","met:5":"3"},
{"dim:1":"2017-01-04","dim:2":"2017-01-04","met:1":"4","met:3":"4","met:5":"4"},
{"dim:1":"2017-01-05","dim:2":"2017-01-05","met:1":"5","met:3":"5","met:5":"5"}
{"dim:2":"1","met:5":"1","met:6":"1"},
{"dim:2":"2","met:5":"2","met:6":"2"},
{"dim:2":"3","met:5":"3","met:6":"3"},
{"dim:2":"4","met:5":"4","met:6":"4"},
{"dim:2":"5","met:5":"5","met:6":"5"}
]
[
{"dim:4":"dim:4:1","dim:5":"dim:5:1","met:3":"1","met:4":"1","met:7":"1"},
{"dim:4":"dim:4:2","dim:5":"dim:5:2","met:3":"2","met:4":"2","met:7":"2"},
{"dim:4":"dim:4:3","dim:5":"dim:5:3","met:3":"3","met:4":"3","met:7":"3"},
{"dim:4":"dim:4:4","dim:5":"dim:5:4","met:3":"4","met:4":"4","met:7":"4"},
{"dim:4":"dim:4:5","dim:5":"dim:5:5","met:3":"5","met:4":"5","met:7":"5"}
{"dim:2":"1","dim:3":"dim:3:1","dim:4":"dim:4:1"},
{"dim:2":"2","dim:3":"dim:3:2","dim:4":"dim:4:2"},
{"dim:2":"3","dim:3":"dim:3:3","dim:4":"dim:4:3"},
{"dim:2":"4","dim:3":"dim:3:4","dim:4":"dim:4:4"},
{"dim:2":"5","dim:3":"dim:3:5","dim:4":"dim:4:5"}
]
[
{"dim:3":"1","dim:4":"dim:4:1","dim:5":"dim:5:1","dim:6":"t","met:6":"1","met:7":"1"},
{"dim:3":"2","dim:4":"dim:4:2","dim:5":"dim:5:2","dim:6":"t","met:6":"2","met:7":"2"},
{"dim:3":"3","dim:4":"dim:4:3","dim:5":"dim:5:3","dim:6":"f","met:6":"3","met:7":"3"},
{"dim:3":"4","dim:4":"dim:4:4","dim:5":"dim:5:4","dim:6":"f","met:6":"4","met:7":"4"},
{"dim:3":"5","dim:4":"dim:4:5","dim:5":"dim:5:5","dim:6":"f","met:6":"5","met:7":"5"}
{"dim:2":"1","dim:7":"1","dim:8":"1"},
{"dim:2":"2","dim:7":"2","dim:8":"2"},
{"dim:2":"3","dim:7":"3","dim:8":"3"},
{"dim:2":"4","dim:7":"4","dim:8":"4"},
{"dim:2":"5","dim:7":"5","dim:8":"5"}
]
[
{"dim:1":"2017-01-01","dim:2":"2017-01-01","dim:7":"1","met:2":"1","met:3":"1","met:8":"1"},
{"dim:1":"2017-01-02","dim:2":"2017-01-02","dim:7":"2","met:2":"2","met:3":"2","met:8":"2"},
{"dim:1":"2017-01-03","dim:2":"2017-01-03","dim:7":"3","met:2":"3","met:3":"3","met:8":"3"},
{"dim:1":"2017-01-04","dim:2":"2017-01-04","dim:7":"4","met:2":"4","met:3":"4","met:8":"4"},
{"dim:1":"2017-01-05","dim:2":"2017-01-05","dim:7":"5","met:2":"5","met:3":"5","met:8":"5"}
{"dim:3":"dim:3:1","met:7":"1"},
{"dim:3":"dim:3:2","met:7":"2"},
{"dim:3":"dim:3:3","met:7":"3"},
{"dim:3":"dim:3:4","met:7":"4"},
{"dim:3":"dim:3:5","met:7":"5"}
]
[
{"dim:1":"2017-01-01","dim:2":"2017-01-01","met:1":"1","met:4":"1"},
{"dim:1":"2017-01-02","dim:2":"2017-01-02","met:1":"2","met:4":"2"},
{"dim:1":"2017-01-03","dim:2":"2017-01-03","met:1":"3","met:4":"3"},
{"dim:1":"2017-01-04","dim:2":"2017-01-04","met:1":"4","met:4":"4"},
{"dim:1":"2017-01-05","dim:2":"2017-01-05","met:1":"5","met:4":"5"}
{"dim:4":"dim:4:1","met:8":"1"},
{"dim:4":"dim:4:2","met:8":"2"},
{"dim:4":"dim:4:3","met:8":"3"},
{"dim:4":"dim:4:4","met:8":"4"},
{"dim:4":"dim:4:5","met:8":"5"}
]
[
{"dim:8":"1","dim:9":"2017-01-01","dim:10":"dim:5:1","met:8":"1"},
{"dim:8":"2","dim:9":"2017-01-02","dim:10":"dim:5:2","met:8":"2"},
{"dim:8":"3","dim:9":"2017-01-03","dim:10":"dim:5:3","met:8":"3"},
{"dim:8":"4","dim:9":"2017-01-04","dim:10":"dim:5:4","met:8":"4"},
{"dim:8":"5","dim:9":"2017-01-05","dim:10":"dim:5:5","met:8":"5"}
{"dim:4":"dim:4:1","dim:5":"t","dim:6":"1"},
{"dim:4":"dim:4:2","dim:5":"t","dim:6":"2"},
{"dim:4":"dim:4:3","dim:5":"t","dim:6":"3"},
{"dim:4":"dim:4:4","dim:5":"f","dim:6":"4"},
{"dim:4":"dim:4:5","dim:5":"f","dim:6":"5"}
]
[
{"dim:8":"1","dim:9":"2017-01-01","dim:10":"dim:5:1","met:9":"1"},
{"dim:8":"2","dim:9":"2017-01-02","dim:10":"dim:5:2","met:9":"2"},
{"dim:8":"3","dim:9":"2017-01-03","dim:10":"dim:5:3","met:9":"3"},
{"dim:8":"4","dim:9":"2017-01-04","dim:10":"dim:5:4","met:9":"4"},
{"dim:8":"5","dim:9":"2017-01-05","dim:10":"dim:5:5","met:9":"5"}
{"dim:5":"t","dim:6":"1","met:9":"1"},
{"dim:5":"t","dim:6":"2","met:9":"2"},
{"dim:5":"t","dim:6":"3","met:9":"3"},
{"dim:5":"f","dim:6":"4","met:9":"4"},
{"dim:5":"f","dim:6":"5","met:9":"5"}
]
[
{"dim:8":"1","dim:9":"2017-01-01","dim:10":"dim:5:1","met:10":"1"},
{"dim:8":"2","dim:9":"2017-01-02","dim:10":"dim:5:2","met:10":"2"},
{"dim:8":"3","dim:9":"2017-01-03","dim:10":"dim:5:3","met:10":"3"},
{"dim:8":"4","dim:9":"2017-01-04","dim:10":"dim:5:4","met:10":"4"},
{"dim:8":"5","dim:9":"2017-01-05","dim:10":"dim:5:5","met:10":"5"}
]
......@@ -29,6 +29,8 @@ interface EngineScenario {
metrics: Metric[];
dimensions: Dimension[];
subDimensions: Dimension[];
wrongMet: Metric;
wrongDim: Dimension;
views: View[];
}
......@@ -61,7 +63,7 @@ const wrongMet = new Metric({
const wrongDim = new Dimension({ name: "dim:11", dataType: "integer" });
const subdimAux = new Dimension({
name: "sub:1",
name: "sub:0",
dataType: "integer",
parent: dims[0],
relation: RelationType.DAY
......@@ -70,25 +72,25 @@ const subdimAux = new Dimension({
const subdims = [
subdimAux,
new Dimension({
name: "sub:2",
name: "sub:1",
dataType: "integer",
parent: dims[8],
parent: dims[1],
relation: RelationType.DAY
}),
new Dimension({
name: "sub:3",
name: "sub:2",
dataType: "integer",
parent: subdimAux,
relation: RelationType.DAY
}),
new Dimension({
name: "sub:4",
name: "sub:3",
dataType: "integer",
parent: null,
relation: RelationType.DAY
}),
new Dimension({
name: "sub:5",
name: "sub:4",
dataType: "integer",
parent: dims[1],
relation: RelationType.DAY
......@@ -97,97 +99,31 @@ const subdims = [
const dateSubDim = [
new Dimension ({
name: "dim:2:month",
name: "dim:0:month",
dataType: "integer",
parent: dims[1],
parent: dims[0],
relation: RelationType.MONTH
}),
new Dimension ({
name: "dim:2:day",
name: "dim:0:day",
dataType: "integer",
parent: dims[1],
parent: dims[0],
relation: RelationType.DAY
}),
new Dimension ({
name: "dim:2:year",
name: "dim:0:year",
dataType: "integer",
parent: dims[1],
parent: dims[0],
relation: RelationType.YEAR
}),
new Dimension ({
name: "dim:2:dow",
name: "dim:0:dow",
dataType: "integer",
parent: dims[1],
parent: dims[0],
relation: RelationType.DAYOFWEEK
}),
];
const engAuxView = [
new View({
metrics: [mets[0], mets[1], mets[2], mets[3], mets[4]],
dimensions: [dims[0], dims[1]],
materialized: false,
childViews: [
{
view: views[0],
metrics: [mets[0], mets[1], mets[2]],
dimensions: [dims[0], dims[1]]
},
{
view: views[5],
metrics: [mets[3]],
dimensions: []
},
{
view: views[1],
metrics: [mets[4]],
dimensions: []
}
]
}),
new View({
metrics: [mets[7], mets[8], mets[9]],
dimensions: [dims[7], dims[8], dims[9]],
materialized: false,
childViews: [
{
view: views[6],
metrics: [mets[7]],
dimensions: [dims[7], dims[8], dims[9]]
},
{
view: views[7],
metrics: [mets[8]],
dimensions: []
},
{
view: views[8],
metrics: [mets[9]],
dimensions: []
}
]
}),
new View({
metrics: [mets[0]],
dimensions: [subdims[0], subdims[1]],
materialized: false,
childViews: [
{
view: views[0],
metrics: [mets[0]],
dimensions: [dims[0]]
},
{
view: views[9],
metrics: [],
dimensions: [dims[8]]
}
]
})
];
const dateView = new View({
metrics: [],
dimensions: dateSubDim,
......@@ -195,52 +131,57 @@ const dateView = new View({
childViews: [{
view: views[0],
metrics: [],
dimensions: [dims[1]]
dimensions: [dims[0]]
}]
});
const subDimView = new View({
metrics: [mets[0]],
dimensions: [subdims[0], subdims[1]],
dimensions: [subdims[0], subdims[1], dims[7], dims[8]],
materialized: false,
childViews: [
{
view: views[0],
metrics: [mets[0]],
dimensions: [dims[0]]
dimensions: [dims[0], dims[7]]
},
{
view: views[8],
view: views[1],
metrics: [],
dimensions: [dims[8]]
dimensions: [dims[1], dims[8]]
},
{
view: views[4],
metrics: [],
dimensions: []
}
]
});
const join4View = new View({
metrics: mets,
dimensions: dims,
metrics: [mets[0], mets[1], mets[2], mets[3], mets[4], mets[5]],
dimensions: [dims[2], dims[7], dims[8]],
materialized: false,
childViews: [
{
view: engAuxView[0],
metrics: [mets[0], mets[1], mets[2], mets[3], mets[4]],
dimensions: [dims[0], dims[1]]
view: views[0],
metrics: [mets[0], mets[1], mets[2]],
dimensions: [dims[7]]
},
{
view: engAuxView[1],
metrics: [mets[7], mets[8], mets[9]],
dimensions: [dims[7], dims[8], dims[9]]
view: views[1],
metrics: [mets[3], mets[4]],
dimensions: [dims[8]]
},
{
view: views[3],
view: views[2],
metrics: [mets[5], mets[6]],
dimensions: [dims[2], dims[3], dims[4], dims[5]]
dimensions: [dims[2]]
},
{
view: views[4],
metrics: [],
dimensions: [dims[6]]
dimensions: []
}
]
});
......@@ -256,7 +197,7 @@ const noSelView = new View({
dimensions: []
},
{
view: views[2],
view: views[1],
metrics: [mets[3]],
dimensions: []
}
......@@ -264,28 +205,30 @@ const noSelView = new View({
});
const withSelView = new View({
metrics: [mets[0], mets[1], mets[4]],
dimensions: [dims[0], dims[1]],
metrics: [mets[0], mets[1]],
dimensions: [dims[7], dims[8]],
materialized: false,
childViews: [
{