From 28c72dcc52b65f5a866509c7fcca125cca32eca2 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:16:33 -0400 Subject: [PATCH] fix: test bugs Signed-off-by: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> --- apps/linkos/src/http/api/LinkAPI.ts | 24 +++++++++++--------- e2e/tests/links.ts | 35 ++++++++++++++++++++++++----- e2e/tests/test.spec.ts | 2 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/apps/linkos/src/http/api/LinkAPI.ts b/apps/linkos/src/http/api/LinkAPI.ts index faa80b1..056cd34 100644 --- a/apps/linkos/src/http/api/LinkAPI.ts +++ b/apps/linkos/src/http/api/LinkAPI.ts @@ -16,7 +16,7 @@ import Links from "@/http/api/Links.ts"; export default class LinkAPI { private static readonly LINKS_TABLE = 'links'; private static producer: Producer | false; - private static readonly path = '/usr/server/app/src/assets/'; + private static readonly path = '/usr/server/app/src/assets/'; public static async init() { LinkAPI.producer = await KafkaProvider.initProducer(); @@ -172,16 +172,20 @@ export default class LinkAPI { linkID = linkID.replace(/\+$/, ''); let shortLink: Link | undefined = undefined; + const linkFormRedis = await RedisProvider.getClient().get(linkID); - const linkFormRedis = await RedisProvider.getClient().get(linkID); - - if (linkFormRedis !== null) { - shortLink = Global.ParseOrFalse(linkFormRedis); - } else { - const link = await P.db(LinkAPI.LINKS_TABLE).where('short', linkID); - - shortLink = link[0]; - await RedisProvider.getClient().set(linkID, JSON.stringify(shortLink)); + try { + if (linkFormRedis !== null) { + shortLink = Global.ParseOrFalse(linkFormRedis); + } else { + const link = await P.db(LinkAPI.LINKS_TABLE).where('short', linkID); + + console.log(P.db(LinkAPI.LINKS_TABLE).where('short', linkID).toQuery()); + shortLink = link[0]; + await RedisProvider.getClient().set(linkID, JSON.stringify(shortLink)); + } + } catch (e: any) { + Log.debug(e); } return shortLink; diff --git a/e2e/tests/links.ts b/e2e/tests/links.ts index aeef7e4..ad2957c 100644 --- a/e2e/tests/links.ts +++ b/e2e/tests/links.ts @@ -8,7 +8,8 @@ interface response { } let generatedLinkId = 0; -const short = 'ga'; +let deletingId = 0; +const short = 'gh'; describe('Adding links', () => { test("Adding link", async () => { const res = await fetch(`${apiEndpoint}/links/`, { @@ -37,6 +38,33 @@ describe('Adding links', () => { generatedLinkId = json.data.id; }); + test("Adding link for deleting", async () => { + const res = await fetch(`${apiEndpoint}/links/`, { + headers: {'x-linkos-token': 'token'}, + method : 'POST', + body : JSON.stringify({ + dest : "https://github.com/", + description : "GitHub", + short : `${short}deleting`, + password : false, + title : "Testing GitHub link", + user_id : "1", + campaign_id : null, + password_protected : false, + expiring_link : false, + informal_redirection: false, + monitor : false, + plus_enabled : false, + },) + }); + + const json: any = await res.json(); + + expect(res.status).toBe(200); + expect(json.success).toBe(true) + deletingId = json.data.id; + }); + test("Adding link with password", async () => { const res = await fetch(`${apiEndpoint}/links/`, { headers: {'x-linkos-token': 'token'}, @@ -61,7 +89,6 @@ describe('Adding links', () => { expect(res.status).toBe(200); expect(json.success).toBe(true) - generatedLinkId = json.data.id; }); test("Adding link with already passed date", async () => { @@ -84,7 +111,6 @@ describe('Adding links', () => { expect(res.status).toBe(200); expect(json.success).toBe(true) - generatedLinkId = json.data.id; }); test("Adding link with plus page and informal redirect", async () => { @@ -108,7 +134,6 @@ describe('Adding links', () => { expect(res.status).toBe(200); expect(json.success).toBe(true) - generatedLinkId = json.data.id; }); }); describe('Getting links', () => { @@ -175,7 +200,7 @@ describe('Manipulating links', () => { }); test("Deleting link", async () => { - const res = await fetch(`${apiEndpoint}/links/${generatedLinkId}/gh`, { + const res = await fetch(`${apiEndpoint}/links/${deletingId}/${short}deleting`, { headers: {'x-linkos-token': 'token'}, method : 'DELETE', }); diff --git a/e2e/tests/test.spec.ts b/e2e/tests/test.spec.ts index cc90497..333fd15 100644 --- a/e2e/tests/test.spec.ts +++ b/e2e/tests/test.spec.ts @@ -1,4 +1,4 @@ -import './basic.ts' +// import './basic.ts' import './links.ts' import './campaigns.ts' import './users.ts'