Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Aug 5, 2024
1 parent 33a0981 commit f3f3031
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 36 deletions.
4 changes: 4 additions & 0 deletions src/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class rest_api {
nickname: 'home',
owner: '',
type: 0,
emojis: [],
stickers: [],
});

this.chat_cache.set('livechat', {
Expand All @@ -75,6 +77,8 @@ export class rest_api {
nickname: 'livechat',
owner: '',
type: 0,
emojis: [],
stickers: [],
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions tests/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -255,7 +257,9 @@ Deno.test('chat messages', async (i) => {
});

await assertRejects(async () => {
await c.send_message('test');
await c.send_message({
content: 'test',
});
});
});

Expand Down
2 changes: 2 additions & 0 deletions tests/internal/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ export const regular_chat: api_chat = {
'nickname': 'test',
'owner': 'test',
'type': chat_type.chat,
'emojis': [],
'stickers': [],
};
14 changes: 4 additions & 10 deletions tests/internal/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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: [],
};
33 changes: 9 additions & 24 deletions tests/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand All @@ -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) => {
Expand All @@ -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',
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
});
Expand All @@ -265,7 +248,9 @@ Deno.test('post reply', async (i) => {
});

await assertRejects(async () => {
await p.reply('test');
await p.reply({
content: 'test',
});
});
});
});

0 comments on commit f3f3031

Please sign in to comment.