Skip to content

Commit

Permalink
fix all e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tot-kristian committed Jul 9, 2024
1 parent 1996a34 commit 8968efa
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 44 deletions.
31 changes: 23 additions & 8 deletions test/e2e.deleteEntitites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,46 @@ 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";
const entityName2 = "testProject2";
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);

Expand All @@ -50,13 +57,17 @@ describe("Nodb delete entities/entity tests", () => {
await expect(
nodb.getEntity({
entityName,
appName,
envName,
entityId: projectPhoenixId,
}),
).rejects.toThrow(NodbError);

await expect(
nodb.getEntity({
entityName,
appName,
envName,
entityId: projectPegasusId,
}),
).rejects.toThrow(NodbError);
Expand All @@ -65,13 +76,17 @@ describe("Nodb delete entities/entity tests", () => {
test("should delete entity", async () => {
const deleted = await nodb.deleteEntity({
entityName: entityName2,
appName,
envName,
entityId: ids[2]!,
});

expect(deleted).toBe(true);
await expect(
nodb.getEntity({
entityName,
appName,
envName,
entityId: ids[2]!,
}),
).rejects.toThrow(NodbError);
Expand Down
33 changes: 22 additions & 11 deletions test/e2e.getEntities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,54 @@ 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";
const entityName2 = "testProject2";
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,
Expand All @@ -61,15 +70,15 @@ 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],
});

expect(second).toStrictEqual({
...projectPegasus,
__meta: {
self: `/${app}/${env}/${entityName}/${ids[1]}`,
self: `/${appName}/${envName}/${entityName}/${ids[1]}`,
},
id: ids[1],
});
Expand All @@ -78,14 +87,16 @@ describe("Nodb get entities/entity tests", () => {
test("should get entity", async () => {
const entity = await nodb.getEntity({
entityName: entityName2,
appName,
envName,
entityId: ids[2]!,
});

expect(entity).toStrictEqual({
...projectTitan,
id: ids[2]!,
__meta: {
self: `/${app}/${env}/${entityName2}/${ids[2]}`,
self: `/${appName}/${envName}/${entityName2}/${ids[2]}`,
},
});
});
Expand Down
28 changes: 21 additions & 7 deletions test/e2e.rag.test.ts
Original file line number Diff line number Diff line change
@@ -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?",
});

Expand Down
36 changes: 27 additions & 9 deletions test/e2e.replaceEntities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]! },
Expand All @@ -55,48 +65,56 @@ 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,
});

expect(insertedProjectPhoenix).toStrictEqual({
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,
});

expect(insertedProjectPegasus).toStrictEqual({
id: projectPegasusId,
title: "Project Pegasus V2",
__meta: {
self: `/${app}/${env}/${entityName}/${projectPegasusId}`,
self: `/${appName}/${envName}/${entityName}/${projectPegasusId}`,
},
});
});

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,
});

expect(insertedProjectTitan).toStrictEqual({
id: insertedProjectId,
title: "Project Titan V2",
__meta: {
self: `/${app}/${env}/${entityName}/${insertedProjectId}`,
self: `/${appName}/${envName}/${entityName}/${insertedProjectId}`,
},
});
});
Expand Down
Loading

0 comments on commit 8968efa

Please sign in to comment.