Skip to content

Commit

Permalink
fix e2e.writeEntities.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tot-kristian committed Jul 9, 2024
1 parent aaa8cd7 commit 1996a34
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions test/e2e.writeEntities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@ import path from "path";
dotenv.config({ path: path.resolve(__dirname, "../.env.test") });

describe("Nodb write 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";

beforeAll(async () => {
const result = await nodb.createAppWithEnvironmentAndGetTokens({
appName,
environmentName: envName,
});

nodb.setToken(result.applicationTokens[0]!.key);
});

afterAll(async () => {
await nodb.deleteEntities({ entityName });
await nodb.deleteApplication({ appName });
});

test("should create entities", async () => {
const result = await nodb.writeEntities({
entityName,
appName,
envName,
payload: [projectPhoenix, projectPegasus],
});

Expand All @@ -39,49 +47,57 @@ describe("Nodb write 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({
...projectPhoenix,
id: projectPhoenixId,
__meta: {
self: `/${app}/${env}/${entityName}/${projectPhoenixId}`,
self: `/${appName}/${envName}/${entityName}/${projectPhoenixId}`,
},
});

const insertedProjectPegasus = await nodb.getEntity({
entityName,
appName,
envName,
entityId: projectPegasusId,
});

expect(insertedProjectPegasus).toStrictEqual({
...projectPegasus,
id: projectPegasusId,
__meta: {
self: `/${app}/${env}/${entityName}/${projectPegasusId}`,
self: `/${appName}/${envName}/${entityName}/${projectPegasusId}`,
},
});
});

test("should create entity", async () => {
const insertedProjectId = await nodb.writeEntity({
entityName,
appName,
envName,
payload: projectTitan,
});

expect(typeof insertedProjectId).toBe("string");

const insertedProjectTitan = await nodb.getEntity({
entityName,
appName,
envName,
entityId: insertedProjectId,
});

expect(insertedProjectTitan).toStrictEqual({
...projectTitan,
id: insertedProjectId,
__meta: {
self: `/${app}/${env}/${entityName}/${insertedProjectId}`,
self: `/${appName}/${envName}/${entityName}/${insertedProjectId}`,
},
});
});
Expand Down

0 comments on commit 1996a34

Please sign in to comment.