Some more quick modifications to test re-factor before PR.

This commit is contained in:
mike12345567 2021-03-05 11:24:15 +00:00
parent 78c550ff30
commit af3d84a1d9
5 changed files with 54 additions and 57 deletions

View File

@ -5,8 +5,7 @@ const {
clearAllAutomations,
} = require("./utilities/TestFunctions")
const { basicAutomation } = require("./utilities/structures")
const { delay } = require("./testUtils")
const { delay } = require("./utilities")
const MAX_RETRIES = 4

View File

@ -1 +0,0 @@
module.exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms))

View File

@ -8,5 +8,5 @@ module.exports = {
user: require("../../../controllers/user"),
automation: require("../../../controllers/automation"),
datasource: require("../../../controllers/datasource"),
query: require("../../../controllers/query")
query: require("../../../controllers/query"),
}

View File

@ -1,3 +1,5 @@
const TEST_CLIENT_ID = "test-client-id"
exports.TEST_CLIENT_ID = TEST_CLIENT_ID
exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms))

View File

@ -1,30 +1,27 @@
const TestConfig = require("./utilities/TestConfiguration");
const TestConfig = require("./utilities/TestConfiguration")
describe("/views", () => {
let request;
let app;
let config;
let appId;
let table;
let request
let config
let table
beforeAll(async () => {
config = new TestConfig();
request = config.request;
});
config = new TestConfig()
request = config.request
})
beforeEach(async () => {
app = await config.init();
appId = app.instance._id;
});
await config.init()
})
afterAll(() => {
config.end();
});
config.end()
})
describe("create", () => {
beforeEach(async () => {
table = await config.createTable();
});
table = await config.createTable()
})
it("returns a success message when the view is successfully created", async () => {
const res = await request
@ -37,12 +34,12 @@ describe("/views", () => {
})
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200);
.expect(200)
expect(res.res.statusMessage).toEqual(
"View TestView saved successfully."
);
});
)
})
it("updates the table row with the new view metadata", async () => {
const res = await request
@ -55,12 +52,12 @@ describe("/views", () => {
})
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200);
.expect(200)
expect(res.res.statusMessage).toEqual(
"View TestView saved successfully."
);
const updatedTable = await config.getTable(table._id);
)
const updatedTable = await config.getTable(table._id)
expect(updatedTable.views).toEqual({
TestView: {
field: "Price",
@ -91,14 +88,14 @@ describe("/views", () => {
},
},
},
});
});
});
})
})
})
describe("fetch", () => {
beforeEach(async () => {
table = await config.createTable();
});
table = await config.createTable()
})
it("returns only custom views", async () => {
await config.createView({
@ -106,21 +103,21 @@ describe("/views", () => {
field: "Price",
calculation: "stats",
tableId: table._id,
});
})
const res = await request
.get(`/api/views`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200);
expect(res.body.length).toBe(1);
expect(res.body.find(({ name }) => name === "TestView")).toBeDefined();
});
});
.expect(200)
expect(res.body.length).toBe(1)
expect(res.body.find(({ name }) => name === "TestView")).toBeDefined()
})
})
describe("query", () => {
beforeEach(async () => {
table = await config.createTable();
});
table = await config.createTable()
})
it("returns data for the created view", async () => {
await config.createView({
@ -128,27 +125,27 @@ describe("/views", () => {
field: "Price",
calculation: "stats",
tableId: table._id,
});
})
await config.createRow({
tableId: table._id,
Price: 1000,
});
})
await config.createRow({
tableId: table._id,
Price: 2000,
});
})
await config.createRow({
tableId: table._id,
Price: 4000,
});
})
const res = await request
.get(`/api/views/TestView?calculation=stats`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200);
expect(res.body.length).toBe(1);
expect(res.body).toMatchSnapshot();
});
.expect(200)
expect(res.body.length).toBe(1)
expect(res.body).toMatchSnapshot()
})
it("returns data for the created view using a group by", async () => {
await config.createView({
@ -157,30 +154,30 @@ describe("/views", () => {
field: "Price",
groupBy: "Category",
tableId: table._id,
});
})
await config.createRow({
tableId: table._id,
Price: 1000,
Category: "One",
});
})
await config.createRow({
tableId: table._id,
Price: 2000,
Category: "One",
});
})
await config.createRow({
tableId: table._id,
Price: 4000,
Category: "Two",
});
})
const res = await request
.get(`/api/views/TestView?calculation=stats&group=Category`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200);
.expect(200)
expect(res.body.length).toBe(2);
expect(res.body).toMatchSnapshot();
});
});
});
expect(res.body.length).toBe(2)
expect(res.body).toMatchSnapshot()
})
})
})