Skip to content

Commit

Permalink
test: add tests for the api routes (#3666)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiTaggart authored Dec 11, 2023
1 parent 71c481a commit 6a4f6e1
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/on_deployment_status_cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
OPENAI_API_SECRET: ${{ secrets.OPENAI_API_SECRET }}
USE_CYPRESS_VRT: false

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/on_pull_request_cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
AIRTABLE_APIKEY: ${{ secrets.AIRTABLE_APIKEY }}
AIRTABLE_BASEID: ${{ secrets.AIRTABLE_BASEID }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_SECRET: ${{ secrets.OPENAI_API_SECRET }}
CYPRESS_BASE_URL: http://localhost:3000
SUPABASE_KEY: ${{ secrets.SUPABASE_STAGING_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_STAGING_URL }}
Expand Down
1 change: 1 addition & 0 deletions cypress.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
env: {
USE_CYPRESS_VRT: process.env.USE_CYPRESS_VRT,
CYPRESS_BASE_URL: process.env.CYPRESS_BASE_URL,
OPENAI_API_SECRET: process.env.OPENAI_API_SECRET,
},
viewportWidth: 1440,
viewportHeight: 1440,
Expand Down
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
env: {
USE_CYPRESS_VRT: process.env.USE_CYPRESS_VRT,
CYPRESS_BASE_URL: process.env.CYPRESS_BASE_URL,
OPENAI_API_SECRET: process.env.OPENAI_API_SECRET,
},
viewportWidth: 1440,
viewportHeight: 1440,
Expand Down
11 changes: 11 additions & 0 deletions cypress/integration/api/ai.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
context("POST /api/ai", () => {
it("gets an ai response for a given prompty", () => {
cy.request("POST", "/api/ai", {
prompt: "How do I create a primary button",
secret: Cypress.env("OPENAI_API_SECRET"),
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).length.to.be.greaterThan(1);
});
});
});
8 changes: 8 additions & 0 deletions cypress/integration/api/discussions-search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
context("GET /api/discussions-search", () => {
it("gets a list of discussions", () => {
cy.request("POST", "/api/discussions-search", { prompt: "creating a button" }).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.data).length.to.be.greaterThan(1);
});
});
});
8 changes: 8 additions & 0 deletions cypress/integration/api/docs-search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
context("GET /api/docs-search", () => {
it("gets a list of docs", () => {
cy.request("POST", "/api/docs-search", { prompt: "creating a button" }).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.data).length.to.be.greaterThan(1);
});
});
});
9 changes: 9 additions & 0 deletions cypress/integration/api/og-image.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
context("GET /api/og-image", () => {
it("gets an image", () => {
cy.request("GET", "/api/og-image?componentRequested=primitives/box").then((response) => {
expect(response.status).to.eq(200);
expect(response.headers["content-type"]).to.eq("image/png");
console.log(response);
});
});
});
31 changes: 31 additions & 0 deletions cypress/integration/api/paste-assistant-message.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
context("POST /api/paste-assistant-message", () => {
let threadId: string;

before(() => {
// create a thread for the message
cy.request("POST", "/api/paste-assistant-thread", {}).then((response) => {
threadId = response.body.id;
});
});

after(() => {
// delete the thread
cy.request("DELETE", "/api/paste-assistant-thread", { id: threadId });
});

it("creates an message on an ai thread", () => {
// create a message on the thread
cy.request("POST", "/api/paste-assistant-message", { threadId, message: "create a button" }).then((response) => {
expect(response.status).to.eq(200);
});
});

it("gets messages on an ai thread", () => {
// get messages on the thread
cy.request("GET", `/api/paste-assistant-messages/${threadId}`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.data).length.to.be.greaterThan(0);
expect(response.body.data[0].content[0].text.value).to.eq("create a button");
});
});
});
29 changes: 29 additions & 0 deletions cypress/integration/api/paste-assistant-thread.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
context("POST /api/paste-assistant-thread", () => {
let threadId: string;
it("creates an ai thread", () => {
cy.request("POST", "/api/paste-assistant-thread", {}).then((response) => {
expect(response.status).to.eq(200);
threadId = response.body.id;
});
});
it("updates an ai thread", () => {
cy.request("PUT", "/api/paste-assistant-thread", { id: threadId, metadata: { testKey: "testData" } }).then(
(response) => {
expect(response.status).to.eq(200);
expect(response.body.metadata.testKey).to.eq("testData");
},
);
});
it("gets an ai thread", () => {
cy.request("GET", `/api/paste-assistant-thread/${threadId}`).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.metadata.testKey).to.eq("testData");
});
});
it("deletes an ai thread", () => {
cy.request("DELETE", "/api/paste-assistant-thread", { id: threadId }).then((response) => {
expect(response.status).to.eq(200);
expect(response.body.deleted).to.eq(true);
});
});
});

1 comment on commit 6a4f6e1

@vercel
Copy link

@vercel vercel bot commented on 6a4f6e1 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.