From a64d441662550605a64e08f463b985a4e3b96fc3 Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Mon, 2 Sep 2024 13:28:55 +0330 Subject: [PATCH] Updated tests --- src/controllers/utils/types.test.ts | 2 +- src/test/store.test.ts | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/controllers/utils/types.test.ts b/src/controllers/utils/types.test.ts index 24b8c28..f54a267 100644 --- a/src/controllers/utils/types.test.ts +++ b/src/controllers/utils/types.test.ts @@ -1,6 +1,6 @@ import { orgCountTuplesTypes } from "./types"; -describe.only("parse database query", () => { +describe("parse database query", () => { it("should parse project stats query", () => { const raw = `{"(0x2e22df9a11e06c306ed8f64ca45ceae02efcf8a443371395a78371bc4fb6f722,1)","(0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404,1)"}`; diff --git a/src/test/store.test.ts b/src/test/store.test.ts index 4d4ac09..194363f 100644 --- a/src/test/store.test.ts +++ b/src/test/store.test.ts @@ -1,13 +1,17 @@ import { describe, expect, test, afterAll } from "@jest/globals"; -import { closeConnection, getTestCtx } from "./utils"; +import { closeConnection, getTestCtx, getTestEntityManager } from "./utils"; import { Organisation } from "../model"; describe("simple storage", () => { + beforeAll(async () => { + const em = await getTestEntityManager(); + await em.getRepository(Organisation).delete({}); + }); afterAll(async () => { await closeConnection(); }); - test("sample authorized attest", async () => { + test("should save sample authorized attest", async () => { const ctx = await getTestCtx(); const organization = new Organisation({ id: "schemaUid", @@ -24,4 +28,23 @@ describe("simple storage", () => { expect(fetchOrganization).toBeDefined(); expect(fetchOrganization?.name).toBe("name"); }); + + test("should not fail on upserting the same entity", async () => { + const ctx = await getTestCtx(); + const organization = new Organisation({ + id: "schemaUid", + name: "name", + issuer: "issuer", + }); + + await ctx.store.upsert(organization); + await ctx.store.upsert(organization); + + const fetchOrganization = await ctx.store.findOneBy(Organisation, { + name: "name", + }); + + expect(fetchOrganization).toBeDefined(); + expect(fetchOrganization?.name).toBe("name"); + }); });