Skip to content

Commit

Permalink
fix: test bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Binyamin Yawitz <[email protected]>
  • Loading branch information
byawitz committed Apr 3, 2024
1 parent 853ed3a commit 28c72dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
24 changes: 14 additions & 10 deletions apps/linkos/src/http/api/LinkAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 30 additions & 5 deletions e2e/tests/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/`, {
Expand Down Expand Up @@ -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);

Check failure on line 63 in e2e/tests/links.ts

View workflow job for this annotation

GitHub Actions / E2E API Test

error: expect(received).toBe(expected)

Expected: 200 Received: 401 at /home/runner/work/linkos/linkos/e2e/tests/links.ts:63:9
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'},
Expand All @@ -61,7 +89,6 @@ describe('Adding links', () => {

expect(res.status).toBe(200);

Check failure on line 90 in e2e/tests/links.ts

View workflow job for this annotation

GitHub Actions / E2E API Test

error: expect(received).toBe(expected)

Expected: 200 Received: 401 at /home/runner/work/linkos/linkos/e2e/tests/links.ts:90:9
expect(json.success).toBe(true)
generatedLinkId = json.data.id;
});

test("Adding link with already passed date", async () => {
Expand All @@ -84,7 +111,6 @@ describe('Adding links', () => {

expect(res.status).toBe(200);

Check failure on line 112 in e2e/tests/links.ts

View workflow job for this annotation

GitHub Actions / E2E API Test

error: expect(received).toBe(expected)

Expected: 200 Received: 401 at /home/runner/work/linkos/linkos/e2e/tests/links.ts:112:9
expect(json.success).toBe(true)
generatedLinkId = json.data.id;
});

test("Adding link with plus page and informal redirect", async () => {
Expand All @@ -108,7 +134,6 @@ describe('Adding links', () => {

expect(res.status).toBe(200);

Check failure on line 135 in e2e/tests/links.ts

View workflow job for this annotation

GitHub Actions / E2E API Test

error: expect(received).toBe(expected)

Expected: 200 Received: 401 at /home/runner/work/linkos/linkos/e2e/tests/links.ts:135:9
expect(json.success).toBe(true)
generatedLinkId = json.data.id;
});
});
describe('Getting links', () => {
Expand Down Expand Up @@ -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',
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './basic.ts'
// import './basic.ts'
import './links.ts'
import './campaigns.ts'
import './users.ts'
Expand Down

0 comments on commit 28c72dc

Please sign in to comment.