Some more quick modifications to test re-factor before PR.
This commit is contained in:
parent
9495e08b58
commit
110ae15fb3
|
@ -5,8 +5,7 @@ const {
|
||||||
clearAllAutomations,
|
clearAllAutomations,
|
||||||
} = require("./utilities/TestFunctions")
|
} = require("./utilities/TestFunctions")
|
||||||
const { basicAutomation } = require("./utilities/structures")
|
const { basicAutomation } = require("./utilities/structures")
|
||||||
|
const { delay } = require("./utilities")
|
||||||
const { delay } = require("./testUtils")
|
|
||||||
|
|
||||||
const MAX_RETRIES = 4
|
const MAX_RETRIES = 4
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
module.exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
|
@ -8,5 +8,5 @@ module.exports = {
|
||||||
user: require("../../../controllers/user"),
|
user: require("../../../controllers/user"),
|
||||||
automation: require("../../../controllers/automation"),
|
automation: require("../../../controllers/automation"),
|
||||||
datasource: require("../../../controllers/datasource"),
|
datasource: require("../../../controllers/datasource"),
|
||||||
query: require("../../../controllers/query")
|
query: require("../../../controllers/query"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
const TEST_CLIENT_ID = "test-client-id"
|
const TEST_CLIENT_ID = "test-client-id"
|
||||||
|
|
||||||
exports.TEST_CLIENT_ID = TEST_CLIENT_ID
|
exports.TEST_CLIENT_ID = TEST_CLIENT_ID
|
||||||
|
|
||||||
|
exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
|
|
@ -1,30 +1,27 @@
|
||||||
const TestConfig = require("./utilities/TestConfiguration");
|
const TestConfig = require("./utilities/TestConfiguration")
|
||||||
|
|
||||||
describe("/views", () => {
|
describe("/views", () => {
|
||||||
let request;
|
let request
|
||||||
let app;
|
let config
|
||||||
let config;
|
let table
|
||||||
let appId;
|
|
||||||
let table;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
config = new TestConfig();
|
config = new TestConfig()
|
||||||
request = config.request;
|
request = config.request
|
||||||
});
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
app = await config.init();
|
await config.init()
|
||||||
appId = app.instance._id;
|
})
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
config.end();
|
config.end()
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
table = await config.createTable();
|
table = await config.createTable()
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns a success message when the view is successfully created", async () => {
|
it("returns a success message when the view is successfully created", async () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
|
@ -37,12 +34,12 @@ describe("/views", () => {
|
||||||
})
|
})
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200);
|
.expect(200)
|
||||||
|
|
||||||
expect(res.res.statusMessage).toEqual(
|
expect(res.res.statusMessage).toEqual(
|
||||||
"View TestView saved successfully."
|
"View TestView saved successfully."
|
||||||
);
|
)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("updates the table row with the new view metadata", async () => {
|
it("updates the table row with the new view metadata", async () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
|
@ -55,12 +52,12 @@ describe("/views", () => {
|
||||||
})
|
})
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200);
|
.expect(200)
|
||||||
|
|
||||||
expect(res.res.statusMessage).toEqual(
|
expect(res.res.statusMessage).toEqual(
|
||||||
"View TestView saved successfully."
|
"View TestView saved successfully."
|
||||||
);
|
)
|
||||||
const updatedTable = await config.getTable(table._id);
|
const updatedTable = await config.getTable(table._id)
|
||||||
expect(updatedTable.views).toEqual({
|
expect(updatedTable.views).toEqual({
|
||||||
TestView: {
|
TestView: {
|
||||||
field: "Price",
|
field: "Price",
|
||||||
|
@ -91,14 +88,14 @@ describe("/views", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
table = await config.createTable();
|
table = await config.createTable()
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns only custom views", async () => {
|
it("returns only custom views", async () => {
|
||||||
await config.createView({
|
await config.createView({
|
||||||
|
@ -106,21 +103,21 @@ describe("/views", () => {
|
||||||
field: "Price",
|
field: "Price",
|
||||||
calculation: "stats",
|
calculation: "stats",
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
});
|
})
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/views`)
|
.get(`/api/views`)
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200);
|
.expect(200)
|
||||||
expect(res.body.length).toBe(1);
|
expect(res.body.length).toBe(1)
|
||||||
expect(res.body.find(({ name }) => name === "TestView")).toBeDefined();
|
expect(res.body.find(({ name }) => name === "TestView")).toBeDefined()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("query", () => {
|
describe("query", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
table = await config.createTable();
|
table = await config.createTable()
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns data for the created view", async () => {
|
it("returns data for the created view", async () => {
|
||||||
await config.createView({
|
await config.createView({
|
||||||
|
@ -128,27 +125,27 @@ describe("/views", () => {
|
||||||
field: "Price",
|
field: "Price",
|
||||||
calculation: "stats",
|
calculation: "stats",
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 1000,
|
Price: 1000,
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 2000,
|
Price: 2000,
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 4000,
|
Price: 4000,
|
||||||
});
|
})
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/views/TestView?calculation=stats`)
|
.get(`/api/views/TestView?calculation=stats`)
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200);
|
.expect(200)
|
||||||
expect(res.body.length).toBe(1);
|
expect(res.body.length).toBe(1)
|
||||||
expect(res.body).toMatchSnapshot();
|
expect(res.body).toMatchSnapshot()
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns data for the created view using a group by", async () => {
|
it("returns data for the created view using a group by", async () => {
|
||||||
await config.createView({
|
await config.createView({
|
||||||
|
@ -157,30 +154,30 @@ describe("/views", () => {
|
||||||
field: "Price",
|
field: "Price",
|
||||||
groupBy: "Category",
|
groupBy: "Category",
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 1000,
|
Price: 1000,
|
||||||
Category: "One",
|
Category: "One",
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 2000,
|
Price: 2000,
|
||||||
Category: "One",
|
Category: "One",
|
||||||
});
|
})
|
||||||
await config.createRow({
|
await config.createRow({
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
Price: 4000,
|
Price: 4000,
|
||||||
Category: "Two",
|
Category: "Two",
|
||||||
});
|
})
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/views/TestView?calculation=stats&group=Category`)
|
.get(`/api/views/TestView?calculation=stats&group=Category`)
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200);
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body.length).toBe(2);
|
expect(res.body.length).toBe(2)
|
||||||
expect(res.body).toMatchSnapshot();
|
expect(res.body).toMatchSnapshot()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
Loading…
Reference in New Issue