-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for the rest of the flow api routes
- Loading branch information
Showing
5 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { DataAccessLayer } from "@gram/core/dist/data/dal.js"; | ||
import { _deleteAllTheThings } from "@gram/core/dist/data/utils.js"; | ||
import { randomUUID } from "crypto"; | ||
import request from "supertest"; | ||
import { createTestApp } from "../../../../test-util/app.js"; | ||
import { createSampleModel } from "../../../../test-util/model.js"; | ||
import { sampleUserToken } from "../../../../test-util/sampleTokens.js"; | ||
import { sampleAttributes } from "./post.spec.js"; | ||
|
||
const token = await sampleUserToken(); | ||
|
||
describe("Flow.delete", () => { | ||
let app: any; | ||
let dal: DataAccessLayer; | ||
|
||
let modelId: string; | ||
let dataFlowId: string; | ||
|
||
beforeAll(async () => { | ||
({ app, dal } = await createTestApp()); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await _deleteAllTheThings(dal.pool); | ||
modelId = await createSampleModel(dal); | ||
dataFlowId = randomUUID(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dal.pool.end(); | ||
}); | ||
|
||
it("should return 401 on un-authenticated request", async () => { | ||
const postres = await request(app) | ||
.post(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "Some summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
expect(postres.status).toBe(200); | ||
const flowId = postres.body.flow.id; | ||
|
||
const res = await request(app) | ||
.delete(`/api/v1/flows/${flowId}`).send(); | ||
|
||
expect(res.status).toBe(401); | ||
}); | ||
|
||
it("should return 200", async () => { | ||
const postres = await request(app) | ||
.post(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "Some summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
const flowId = postres.body.flow.id; | ||
|
||
const res = await request(app) | ||
.delete(`/api/v1/flows/${flowId}`) | ||
.set("Authorization", token).send(); | ||
|
||
expect(res.status).toBe(200); | ||
}); | ||
|
||
it("should return 404 with invalid flow id", async () => { | ||
const flowId = randomUUID(); | ||
const res = await request(app) | ||
.delete(`/api/v1/flows/${flowId}`) | ||
.set("Authorization", token).send(); | ||
|
||
expect(res.status).toBe(404); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { DataAccessLayer } from "@gram/core/dist/data/dal.js"; | ||
import { _deleteAllTheThings } from "@gram/core/dist/data/utils.js"; | ||
import { randomUUID } from "crypto"; | ||
import request from "supertest"; | ||
import { createTestApp } from "../../../../test-util/app.js"; | ||
import { createSampleModel } from "../../../../test-util/model.js"; | ||
import { sampleUserToken } from "../../../../test-util/sampleTokens.js"; | ||
import { sampleAttributes } from "./post.spec.js"; | ||
|
||
const token = await sampleUserToken(); | ||
|
||
describe("Flow.get", () => { | ||
let app: any; | ||
let dal: DataAccessLayer; | ||
|
||
let modelId: string; | ||
let dataFlowId: string; | ||
|
||
beforeAll(async () => { | ||
({ app, dal } = await createTestApp()); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await _deleteAllTheThings(dal.pool); | ||
modelId = await createSampleModel(dal); | ||
dataFlowId = randomUUID(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dal.pool.end(); | ||
}); | ||
|
||
it("should return 401 on un-authenticated request", async () => { | ||
const res = await request(app) | ||
.get(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`).send(); | ||
expect(res.status).toBe(401); | ||
}); | ||
|
||
it("should return 200", async () => { | ||
const res = await request(app) | ||
.get(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send(); | ||
|
||
// console.log("res.body", JSON.stringify(res.body)); | ||
|
||
expect(res.status).toBe(200); | ||
expect(res.body.flows).toEqual([]); | ||
|
||
const postres = await request(app) | ||
.post(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "Some summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
const getRes = await request(app) | ||
.get(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send(); | ||
|
||
expect(getRes.status).toBe(200); | ||
expect(getRes.body.flows.length).toBe(1); | ||
expect(getRes.body.flows[0].summary).toBe("Some summary"); | ||
}); | ||
|
||
it("should return 404 with invalid model id", async () => { | ||
const modelId = randomUUID(); | ||
const dataFlowId = randomUUID(); | ||
const res = await request(app) | ||
.get(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token).send(); | ||
|
||
expect(res.status).toBe(404); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { DataAccessLayer } from "@gram/core/dist/data/dal.js"; | ||
import { _deleteAllTheThings } from "@gram/core/dist/data/utils.js"; | ||
import { randomUUID } from "crypto"; | ||
import request from "supertest"; | ||
import { createTestApp } from "../../../../test-util/app.js"; | ||
import { createSampleModel } from "../../../../test-util/model.js"; | ||
import { sampleUserToken } from "../../../../test-util/sampleTokens.js"; | ||
import { sampleAttributes } from "./post.spec.js"; | ||
|
||
const token = await sampleUserToken(); | ||
|
||
describe("Flow.patch", () => { | ||
let app: any; | ||
let dal: DataAccessLayer; | ||
|
||
let modelId: string; | ||
let dataFlowId: string; | ||
|
||
beforeAll(async () => { | ||
({ app, dal } = await createTestApp()); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await _deleteAllTheThings(dal.pool); | ||
modelId = await createSampleModel(dal); | ||
dataFlowId = randomUUID(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dal.pool.end(); | ||
}); | ||
|
||
it("should return 401 on un-authenticated request", async () => { | ||
const postres = await request(app) | ||
.post(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "Some summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
expect(postres.status).toBe(200); | ||
const flowId = postres.body.flow.id; | ||
|
||
const res = await request(app) | ||
.patch(`/api/v1/flows/${flowId}`) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "new summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
expect(res.status).toBe(401); | ||
}); | ||
|
||
it("should return 200", async () => { | ||
const postres = await request(app) | ||
.post(`/api/v1/flows/model/${modelId}/dataflow/${dataFlowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "Some summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
const flowId = postres.body.flow.id; | ||
|
||
const res = await request(app) | ||
.patch(`/api/v1/flows/${flowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "new summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
// console.log("res.body", JSON.stringify(res.body)); | ||
|
||
expect(res.status).toBe(200); | ||
}); | ||
|
||
it("should return 404 with invalid flow id", async () => { | ||
const flowId = Math.floor(Math.random() * 100000000); | ||
const res = await request(app) | ||
.patch(`/api/v1/flows/${flowId}`) | ||
.set("Authorization", token) | ||
.send({ | ||
originComponentId: randomUUID(), | ||
summary: "new summary", | ||
attributes: sampleAttributes(), | ||
}); | ||
|
||
console.log("res.body", JSON.stringify(res.body)); | ||
expect(res.status).toBe(404); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters