From f3f3031a432c450b363f95e6fc7555c60890dac0 Mon Sep 17 00:00:00 2001 From: Jersey Date: Mon, 5 Aug 2024 19:27:31 -0400 Subject: [PATCH] fix tests --- src/api/rest.ts | 4 ++++ src/interfaces/post.ts | 2 ++ tests/chat.ts | 8 ++++++-- tests/internal/chat.ts | 2 ++ tests/internal/post.ts | 14 ++++---------- tests/post.ts | 33 +++++++++------------------------ 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/api/rest.ts b/src/api/rest.ts index 55b3d4c..82e6d7b 100644 --- a/src/api/rest.ts +++ b/src/api/rest.ts @@ -61,6 +61,8 @@ export class rest_api { nickname: 'home', owner: '', type: 0, + emojis: [], + stickers: [], }); this.chat_cache.set('livechat', { @@ -75,6 +77,8 @@ export class rest_api { nickname: 'livechat', owner: '', type: 0, + emojis: [], + stickers: [], }); } diff --git a/src/interfaces/post.ts b/src/interfaces/post.ts index 12a08c9..e2ad308 100644 --- a/src/interfaces/post.ts +++ b/src/interfaces/post.ts @@ -161,9 +161,11 @@ export class post { this.id = this.raw._id; this.pinned = this.raw.pinned; this.deleted = this.raw.isDeleted; + this.content = this.raw.p; this.chat_id = this.raw.post_origin; this.timestamp = this.raw.t.e; this.type = this.raw.type; + this.username = this.raw.u; this.replies = this.raw.reply_to.map((i) => new post({ api_token: this.api_token, diff --git a/tests/chat.ts b/tests/chat.ts index 5862424..5473f3b 100644 --- a/tests/chat.ts +++ b/tests/chat.ts @@ -240,7 +240,9 @@ Deno.test('chat messages', async (i) => { }), }); - const p = await c.send_message('test'); + const p = await c.send_message({ + content: 'test', + }); post_is_api_post(p, regular_post); }); @@ -255,7 +257,9 @@ Deno.test('chat messages', async (i) => { }); await assertRejects(async () => { - await c.send_message('test'); + await c.send_message({ + content: 'test', + }); }); }); diff --git a/tests/internal/chat.ts b/tests/internal/chat.ts index c2726fa..7139954 100644 --- a/tests/internal/chat.ts +++ b/tests/internal/chat.ts @@ -31,4 +31,6 @@ export const regular_chat: api_chat = { 'nickname': 'test', 'owner': 'test', 'type': chat_type.chat, + 'emojis': [], + 'stickers': [], }; diff --git a/tests/internal/post.ts b/tests/internal/post.ts index aff37b9..7ae4b26 100644 --- a/tests/internal/post.ts +++ b/tests/internal/post.ts @@ -15,11 +15,7 @@ export function post_is_api_post(post: post, api_post: api_post) { assertEquals(post.timestamp, api_post.t.e); assertEquals(post.type, api_post.type); assertEquals(post.username, api_post.u); - if (api_post.bridged && post.bridged) { - post_is_api_post(post.bridged, api_post.bridged); - } else { - assertEquals(post.bridged, undefined); - } + assertEquals(post.reactions, api_post.reactions); } export const regular_post: api_post = { @@ -35,9 +31,7 @@ export const regular_post: api_post = { }, type: post_type.normal, u: 'test', -}; - -export const bridged_post: api_post = { - ...regular_post, - bridged: regular_post, + reactions: [], + reply_to: [], + stickers: [], }; diff --git a/tests/post.ts b/tests/post.ts index 2d7748d..5400f4e 100644 --- a/tests/post.ts +++ b/tests/post.ts @@ -5,11 +5,7 @@ import { assertThrows, mockFetch, } from './internal/deps.ts'; -import { - bridged_post, - post_is_api_post, - regular_post, -} from './internal/post.ts'; +import { post_is_api_post, regular_post } from './internal/post.ts'; Deno.test('api_post validation', async (i) => { await i.step('number (invalid)', () => { @@ -24,13 +20,9 @@ Deno.test('api_post validation', async (i) => { assertEquals(is_api_post({}), false); }); - await i.step('post (valid, not bridged)', () => { + await i.step('post (valid)', () => { assertEquals(is_api_post(regular_post), true); }); - - await i.step('post (valid, bridged)', () => { - assertEquals(is_api_post(bridged_post), true); - }); }); Deno.test('post construction', async (i) => { @@ -45,7 +37,7 @@ Deno.test('post construction', async (i) => { }); }); - await i.step('construct valid post (not bridged)', () => { + await i.step('construct valid post', () => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', @@ -55,17 +47,6 @@ Deno.test('post construction', async (i) => { post_is_api_post(p, regular_post); }); - - await i.step('construct valid post (bridged)', () => { - const p = new post({ - api_url: 'http://localhost:8000', - api_token: 'test', - api_username: 'test', - data: bridged_post, - }); - - post_is_api_post(p, bridged_post); - }); }); Deno.test('post pinning', async (i) => { @@ -250,7 +231,9 @@ Deno.test('post reply', async (i) => { body: JSON.stringify(regular_post), }); - const post = await p.reply('test'); + const post = await p.reply({ + content: 'test', + }); post_is_api_post(post, regular_post); }); @@ -265,7 +248,9 @@ Deno.test('post reply', async (i) => { }); await assertRejects(async () => { - await p.reply('test'); + await p.reply({ + content: 'test', + }); }); }); });