From 8968efa0f97724ad41f70257a01e167d89104da8 Mon Sep 17 00:00:00 2001 From: Kristian Tot Date: Tue, 9 Jul 2024 19:14:10 +0200 Subject: [PATCH] fix all e2e tests --- test/e2e.deleteEntitites.test.ts | 31 ++++++++++++++++++++------- test/e2e.getEntities.test.ts | 33 +++++++++++++++++++---------- test/e2e.rag.test.ts | 28 ++++++++++++++++++------- test/e2e.replaceEntities.test.ts | 36 ++++++++++++++++++++++++-------- test/e2e.updateEntities.test.ts | 36 ++++++++++++++++++++++++-------- 5 files changed, 120 insertions(+), 44 deletions(-) diff --git a/test/e2e.deleteEntitites.test.ts b/test/e2e.deleteEntitites.test.ts index 79302ad..8e9c18b 100644 --- a/test/e2e.deleteEntitites.test.ts +++ b/test/e2e.deleteEntitites.test.ts @@ -8,14 +8,11 @@ import { NodbError } from "../src/errors"; dotenv.config({ path: path.resolve(__dirname, "../.env.test") }); describe("Nodb delete entities/entity tests", () => { - const app = process.env.NODB_APP!; - const env = process.env.NODB_ENV!; + const appName = "test-app"; + const envName = "test-env"; const nodb = new Nodb({ - app, - env, baseUrl: process.env.NODB_BASE_URL!, - token: process.env.NODB_JWT_TOKEN!, }); const entityName = "testProject"; @@ -23,24 +20,34 @@ describe("Nodb delete entities/entity tests", () => { let ids: string[] = []; beforeAll(async () => { + const result = await nodb.createAppWithEnvironmentAndGetTokens({ + appName, + environmentName: envName, + }); + + nodb.setToken(result.applicationTokens[0]!.key); + ids = await nodb.writeEntities({ entityName, + appName, + envName, payload: [projectPhoenix, projectPegasus], }); const lastId = await nodb.writeEntity({ entityName: entityName2, + appName, + envName, payload: projectTitan, }); ids.push(lastId); }); afterAll(async () => { - await nodb.deleteEntities({ entityName }); - await nodb.deleteEntities({ entityName: entityName2 }); + await nodb.deleteApplication({ appName }); }); test("should delete entities", async () => { - const result = await nodb.deleteEntities({ entityName }); + const result = await nodb.deleteEntities({ entityName, appName, envName }); expect(result).toBe(2); @@ -50,6 +57,8 @@ describe("Nodb delete entities/entity tests", () => { await expect( nodb.getEntity({ entityName, + appName, + envName, entityId: projectPhoenixId, }), ).rejects.toThrow(NodbError); @@ -57,6 +66,8 @@ describe("Nodb delete entities/entity tests", () => { await expect( nodb.getEntity({ entityName, + appName, + envName, entityId: projectPegasusId, }), ).rejects.toThrow(NodbError); @@ -65,6 +76,8 @@ describe("Nodb delete entities/entity tests", () => { test("should delete entity", async () => { const deleted = await nodb.deleteEntity({ entityName: entityName2, + appName, + envName, entityId: ids[2]!, }); @@ -72,6 +85,8 @@ describe("Nodb delete entities/entity tests", () => { await expect( nodb.getEntity({ entityName, + appName, + envName, entityId: ids[2]!, }), ).rejects.toThrow(NodbError); diff --git a/test/e2e.getEntities.test.ts b/test/e2e.getEntities.test.ts index 126025c..24376e9 100644 --- a/test/e2e.getEntities.test.ts +++ b/test/e2e.getEntities.test.ts @@ -7,14 +7,11 @@ import path from "path"; dotenv.config({ path: path.resolve(__dirname, "../.env.test") }); describe("Nodb get entities/entity tests", () => { - const app = process.env.NODB_APP!; - const env = process.env.NODB_ENV!; + const appName = "test-app"; + const envName = "test-env"; const nodb = new Nodb({ - app, - env, baseUrl: process.env.NODB_BASE_URL!, - token: process.env.NODB_JWT_TOKEN!, }); const entityName = "testProject"; @@ -22,30 +19,42 @@ describe("Nodb get entities/entity tests", () => { let ids: string[] = []; beforeAll(async () => { + const result = await nodb.createAppWithEnvironmentAndGetTokens({ + appName, + environmentName: envName, + }); + + nodb.setToken(result.applicationTokens[0]!.key); + ids = await nodb.writeEntities({ entityName, + appName, + envName, payload: [projectPhoenix, projectPegasus], }); const lastId = await nodb.writeEntity({ entityName: entityName2, + appName, + envName, payload: projectTitan, }); ids.push(lastId); }); afterAll(async () => { - await nodb.deleteEntities({ entityName }); - await nodb.deleteEntities({ entityName: entityName2 }); + await nodb.deleteApplication({ appName }); }); test("should get entities", async () => { const result = await nodb.getEntities({ entityName, + appName, + envName, }); expect(Object.keys(result).sort()).toEqual([entityName, "__meta"].sort()); expect(result["__meta"]).toStrictEqual({ - current_page: `/${app}/${env}/${entityName}?__page=1&__per_page=10`, + current_page: `/${appName}/${envName}/${entityName}?__page=1&__per_page=10`, items: 2, page: 1, pages: 1, @@ -61,7 +70,7 @@ describe("Nodb get entities/entity tests", () => { expect(first).toStrictEqual({ ...projectPhoenix, __meta: { - self: `/${app}/${env}/${entityName}/${ids[0]}`, + self: `/${appName}/${envName}/${entityName}/${ids[0]}`, }, id: ids[0], }); @@ -69,7 +78,7 @@ describe("Nodb get entities/entity tests", () => { expect(second).toStrictEqual({ ...projectPegasus, __meta: { - self: `/${app}/${env}/${entityName}/${ids[1]}`, + self: `/${appName}/${envName}/${entityName}/${ids[1]}`, }, id: ids[1], }); @@ -78,6 +87,8 @@ describe("Nodb get entities/entity tests", () => { test("should get entity", async () => { const entity = await nodb.getEntity({ entityName: entityName2, + appName, + envName, entityId: ids[2]!, }); @@ -85,7 +96,7 @@ describe("Nodb get entities/entity tests", () => { ...projectTitan, id: ids[2]!, __meta: { - self: `/${app}/${env}/${entityName2}/${ids[2]}`, + self: `/${appName}/${envName}/${entityName2}/${ids[2]}`, }, }); }); diff --git a/test/e2e.rag.test.ts b/test/e2e.rag.test.ts index dcf39e6..83ec47d 100644 --- a/test/e2e.rag.test.ts +++ b/test/e2e.rag.test.ts @@ -1,29 +1,43 @@ import Nodb from "../src/nodb"; import dotenv from "dotenv"; import path from "path"; +import { projectPegasus, projectPhoenix } from "./seed"; // Load environment variables from .env.test dotenv.config({ path: path.resolve(__dirname, "../.env.test") }); describe("Nodb rag entities tests ", () => { - const app = process.env.NODB_APP!; - const env = process.env.NODB_ENV!; + const appName = "test-app"; + const envName = "test-env"; const nodb = new Nodb({ - app, - env, baseUrl: process.env.NODB_BASE_URL!, - token: process.env.NODB_JWT_TOKEN!, }); + const entityName = "test-entity"; + beforeAll(async () => { + const result = await nodb.createAppWithEnvironmentAndGetTokens({ + appName, + environmentName: envName, + }); + + nodb.setToken(result.applicationTokens[0]!.key); - const entityName = "testProject"; + await nodb.writeEntities({ + entityName, + appName, + envName, + payload: [projectPhoenix, projectPegasus], + }); + }); afterAll(async () => { - await nodb.deleteEntities({ entityName }); + await nodb.deleteApplication({ appName }); }); test("should return some answer", async () => { const result = await nodb.getInquiry({ + appName, + envName, inquiry: "Which projects do I have available?", }); diff --git a/test/e2e.replaceEntities.test.ts b/test/e2e.replaceEntities.test.ts index 87c233c..fe7ec48 100644 --- a/test/e2e.replaceEntities.test.ts +++ b/test/e2e.replaceEntities.test.ts @@ -7,38 +7,48 @@ import path from "path"; dotenv.config({ path: path.resolve(__dirname, "../.env.test") }); describe("Nodb replace entities/entity tests", () => { - const app = process.env.NODB_APP!; - const env = process.env.NODB_ENV!; + const appName = "test-app"; + const envName = "test-env"; const nodb = new Nodb({ - app, - env, baseUrl: process.env.NODB_BASE_URL!, - token: process.env.NODB_JWT_TOKEN!, }); const entityName = "testProject"; let ids: string[] = []; beforeAll(async () => { + const result = await nodb.createAppWithEnvironmentAndGetTokens({ + appName, + environmentName: envName, + }); + + nodb.setToken(result.applicationTokens[0]!.key); + ids = await nodb.writeEntities({ entityName, + appName, + envName, payload: [projectPhoenix, projectPegasus], }); const lastId = await nodb.writeEntity({ entityName, + appName, + envName, payload: projectTitan, }); ids.push(lastId); }); afterAll(async () => { - await nodb.deleteEntities({ entityName }); + await nodb.deleteApplication({ appName }); }); test("should replace entities", async () => { const result = await nodb.replaceEntities({ entityName, + appName, + envName, payload: [ { title: "Project Phoenix V2", id: ids[0]! }, { title: "Project Pegasus V2", id: ids[1]! }, @@ -55,6 +65,8 @@ describe("Nodb replace entities/entity tests", () => { // get what's in db so we could verify it const insertedProjectPhoenix = await nodb.getEntity({ entityName, + appName, + envName, entityId: projectPhoenixId, }); @@ -62,12 +74,14 @@ describe("Nodb replace entities/entity tests", () => { id: projectPhoenixId, title: "Project Phoenix V2", __meta: { - self: `/${app}/${env}/${entityName}/${projectPhoenixId}`, + self: `/${appName}/${envName}/${entityName}/${projectPhoenixId}`, }, }); const insertedProjectPegasus = await nodb.getEntity({ entityName, + appName, + envName, entityId: projectPegasusId, }); @@ -75,7 +89,7 @@ describe("Nodb replace entities/entity tests", () => { id: projectPegasusId, title: "Project Pegasus V2", __meta: { - self: `/${app}/${env}/${entityName}/${projectPegasusId}`, + self: `/${appName}/${envName}/${entityName}/${projectPegasusId}`, }, }); }); @@ -83,12 +97,16 @@ describe("Nodb replace entities/entity tests", () => { test("should replace entity", async () => { const insertedProjectId = await nodb.replaceEntity({ entityName, + appName, + envName, payload: { title: "Project Titan V2", id: ids[2]! }, }); expect(insertedProjectId).toBe(ids[2]); const insertedProjectTitan = await nodb.getEntity({ entityName, + appName, + envName, entityId: insertedProjectId, }); @@ -96,7 +114,7 @@ describe("Nodb replace entities/entity tests", () => { id: insertedProjectId, title: "Project Titan V2", __meta: { - self: `/${app}/${env}/${entityName}/${insertedProjectId}`, + self: `/${appName}/${envName}/${entityName}/${insertedProjectId}`, }, }); }); diff --git a/test/e2e.updateEntities.test.ts b/test/e2e.updateEntities.test.ts index 7bae7bb..1396d39 100644 --- a/test/e2e.updateEntities.test.ts +++ b/test/e2e.updateEntities.test.ts @@ -7,38 +7,48 @@ import path from "path"; dotenv.config({ path: path.resolve(__dirname, "../.env.test") }); describe("Nodb update entities/entity tests", () => { - const app = process.env.NODB_APP!; - const env = process.env.NODB_ENV!; + const appName = "test-app"; + const envName = "test-env"; const nodb = new Nodb({ - app, - env, baseUrl: process.env.NODB_BASE_URL!, - token: process.env.NODB_JWT_TOKEN!, }); const entityName = "testProject"; let ids: string[] = []; beforeAll(async () => { + const result = await nodb.createAppWithEnvironmentAndGetTokens({ + appName, + environmentName: envName, + }); + + nodb.setToken(result.applicationTokens[0]!.key); + ids = await nodb.writeEntities({ entityName, + appName, + envName, payload: [projectPhoenix, projectPegasus], }); const lastId = await nodb.writeEntity({ entityName, + appName, + envName, payload: projectTitan, }); ids.push(lastId); }); afterAll(async () => { - await nodb.deleteEntities({ entityName }); + await nodb.deleteApplication({ appName }); }); test("should update entities", async () => { const result = await nodb.updateEntities({ entityName, + appName, + envName, payload: [ { title: "Project Phoenix V2", id: ids[0]! }, { title: "Project Pegasus V2", id: ids[1]! }, @@ -55,6 +65,8 @@ describe("Nodb update entities/entity tests", () => { // get what's in db so we could verify it const insertedProjectPhoenix = await nodb.getEntity({ entityName, + appName, + envName, entityId: projectPhoenixId, }); @@ -63,12 +75,14 @@ describe("Nodb update entities/entity tests", () => { id: projectPhoenixId, title: "Project Phoenix V2", __meta: { - self: `/${app}/${env}/${entityName}/${projectPhoenixId}`, + self: `/${appName}/${envName}/${entityName}/${projectPhoenixId}`, }, }); const insertedProjectPegasus = await nodb.getEntity({ entityName, + appName, + envName, entityId: projectPegasusId, }); @@ -77,7 +91,7 @@ describe("Nodb update entities/entity tests", () => { id: projectPegasusId, title: "Project Pegasus V2", __meta: { - self: `/${app}/${env}/${entityName}/${projectPegasusId}`, + self: `/${appName}/${envName}/${entityName}/${projectPegasusId}`, }, }); }); @@ -85,12 +99,16 @@ describe("Nodb update entities/entity tests", () => { test("should update entity", async () => { const insertedProjectId = await nodb.updateEntity({ entityName, + appName, + envName, payload: { title: "Project Titan V2", id: ids[2]! }, }); expect(insertedProjectId).toBe(ids[2]); const insertedProjectTitan = await nodb.getEntity({ entityName, + appName, + envName, entityId: insertedProjectId, }); @@ -99,7 +117,7 @@ describe("Nodb update entities/entity tests", () => { id: insertedProjectId, title: "Project Titan V2", __meta: { - self: `/${app}/${env}/${entityName}/${insertedProjectId}`, + self: `/${appName}/${envName}/${entityName}/${insertedProjectId}`, }, }); });