Skip to content

Commit

Permalink
fix: report test
Browse files Browse the repository at this point in the history
  • Loading branch information
Metololo committed Jul 21, 2024
1 parent 92a6933 commit d1623da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
30 changes: 20 additions & 10 deletions apps/api/test/reports.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'node:fs';
import path from 'node:path';
import app from '../src/index.js';
import { Role } from '../src/validators/general.js';
import { deleteAdmin, insertRole, setValidSubscription } from './utils.js';
Expand Down Expand Up @@ -42,22 +44,30 @@ describe('Report tests', () => {
const loginUser: { token: string } = await loginRes.json();
jwt = loginUser.token;

const postRes = await app.request('/blog/posts', {
const formData = new FormData();

formData.append('title', 'Post test report');
formData.append('description', 'Post test description');
formData.append('content', 'Post test content for reporting');

const imagePath = path.join(__dirname, 'files', 'mock_image.png');
const imageBuffer = fs.readFileSync(imagePath);
const imageBlob = new Blob([imageBuffer], { type: 'image/png' });
formData.append('cover_image', imageBlob, 'mock_image.png');

const resPost = await app.request('/blog/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({
title: 'Post test report',
content: 'Post test content for reporting',
cover_image: 'https://example.com/image.jpg',
description: 'Post test description',
}),
body: formData,
});
expect(postRes.status).toBe(201);
const post = await postRes.json();

expect(resPost.status).toBe(201);
const post: { id: number; title: string; content: string; cover_image: string } = await resPost.json();
id_post = post.id;
expect(post.title).toBe('Post test');

Check failure on line 69 in apps/api/test/reports.test.ts

View workflow job for this annotation

GitHub Actions / api-test

test/reports.test.ts > Report tests

AssertionError: expected 'Post test report' to be 'Post test' // Object.is equality - Expected + Received - Post test + Post test report ❯ test/reports.test.ts:69:24
expect(post.content).toBe('Post test content');

const commentRes = await app.request(`/blog/posts/${id_post}/comments`, {
method: 'POST',
Expand Down
1 change: 0 additions & 1 deletion apps/client/app/ui/components/BlogPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuTrigger,
} from '@ui/components/ui/dropdown-menu';
Expand Down

0 comments on commit d1623da

Please sign in to comment.