Skip to content

Commit

Permalink
refactor: use strictEqual and simplify some asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
zyoshoka committed Sep 19, 2024
1 parent 4a41094 commit 28af0f3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
40 changes: 17 additions & 23 deletions packages/backend/test-federation/test/drive.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepEqual, deepStrictEqual, strictEqual } from 'node:assert';
import { deepStrictEqual, strictEqual } from 'node:assert';
import test, { describe } from 'node:test';
import * as Misskey from 'misskey-js';
import { createAccount, fetchAdmin, uploadFile } from './utils.js';
Expand All @@ -18,14 +18,11 @@ describe('Drive', () => {
const image = await uploadFile('a.local', '../../test/resources/192.jpg', uploader.i);
const noteWithImage = (await uploaderClient.request('notes/create', { fileIds: [image.id] })).createdNote;
const uri = `https://a.local/notes/${noteWithImage.id}`;
const noteInBServer = await (async (): Promise<Misskey.entities.ApShowResponse & { type: 'Note' }> => {
const resolved = await bAdminClient.request('ap/show', { uri });
strictEqual(resolved.type, 'Note');
return resolved;
})();
deepEqual(noteInBServer.object.uri, uri);
deepEqual(noteInBServer.object.files != null, true);
deepEqual(noteInBServer.object.files!.length, 1);
const noteInBServer = await bAdminClient.request('ap/show', { uri });
strictEqual(noteInBServer.type, 'Note');
strictEqual(noteInBServer.object.uri, uri);
strictEqual(noteInBServer.object.files != null, true);
strictEqual(noteInBServer.object.files!.length, 1);
const imageInBServer = noteInBServer.object.files![0];

await test('Check consistency of DriveFile', () => {
Expand Down Expand Up @@ -67,31 +64,28 @@ describe('Drive', () => {
// console.log(`b.local: ${JSON.stringify(updatedImageInBServer, null, '\t')}`);

// FIXME: not updated with `drive/files/update`
deepEqual(updatedImage.isSensitive, true);
deepEqual(updatedImage.name, 'updated_192.jpg');
deepEqual(updatedImageInBServer.isSensitive, false);
deepEqual(updatedImageInBServer.name, '192.jpg');
strictEqual(updatedImage.isSensitive, true);
strictEqual(updatedImage.name, 'updated_192.jpg');
strictEqual(updatedImageInBServer.isSensitive, false);
strictEqual(updatedImageInBServer.name, '192.jpg');
});

const noteWithUpdatedImage = (await uploaderClient.request('notes/create', { fileIds: [updatedImage.id] })).createdNote;
const uriUpdated = `https://a.local/notes/${noteWithUpdatedImage.id}`;
const noteWithUpdatedImageInBServer = await (async (): Promise<Misskey.entities.ApShowResponse & { type: 'Note' }> => {
const resolved = await bAdminClient.request('ap/show', { uri: uriUpdated });
strictEqual(resolved.type, 'Note');
return resolved;
})();
deepEqual(noteWithUpdatedImageInBServer.object.uri, uriUpdated);
deepEqual(noteWithUpdatedImageInBServer.object.files != null, true);
deepEqual(noteWithUpdatedImageInBServer.object.files!.length, 1);
const noteWithUpdatedImageInBServer = await bAdminClient.request('ap/show', { uri: uriUpdated });
strictEqual(noteWithUpdatedImageInBServer.type, 'Note');
strictEqual(noteWithUpdatedImageInBServer.object.uri, uriUpdated);
strictEqual(noteWithUpdatedImageInBServer.object.files != null, true);
strictEqual(noteWithUpdatedImageInBServer.object.files!.length, 1);
const reupdatedImageInBServer = noteWithUpdatedImageInBServer.object.files![0];

await test('Re-update with attaching to Note', async () => {
// console.log(`b.local: ${JSON.stringify(reupdatedImageInBServer, null, '\t')}`);

// `isSensitive` is updated
deepEqual(reupdatedImageInBServer.isSensitive, true);
strictEqual(reupdatedImageInBServer.isSensitive, true);
// FIXME: but `name` is not updated
deepEqual(reupdatedImageInBServer.name, '192.jpg');
strictEqual(reupdatedImageInBServer.name, '192.jpg');
});
});
});
21 changes: 9 additions & 12 deletions packages/backend/test-federation/test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepEqual, deepStrictEqual, strictEqual } from 'node:assert';
import { deepStrictEqual, strictEqual } from 'node:assert';
import test, { before, describe } from 'node:test';
import * as Misskey from 'misskey-js';
import { createAccount, fetchAdmin, resolveRemoteAccount } from './utils.js';
Expand All @@ -25,13 +25,10 @@ describe('User', () => {

const aliceInAServer = await aliceWatcherClient.request('users/show', { userId: alice.id });

const resolved = await (async (): Promise<Misskey.entities.ApShowResponse & { type: 'User' }> => {
const resolved = await aliceWatcherInBServerClient.request('ap/show', {
uri: `https://a.local/@${aliceInAServer.username}`,
});
strictEqual(resolved.type, 'User');
return resolved;
})();
const resolved = await aliceWatcherInBServerClient.request('ap/show', {
uri: `https://a.local/@${aliceInAServer.username}`,
});
strictEqual(resolved.type, 'User');

const aliceInBServer = await aliceWatcherInBServerClient.request('users/show', { userId: resolved.object.id });

Expand Down Expand Up @@ -86,12 +83,12 @@ describe('User', () => {

test('Check consistency with `users/following` and `users/followers` endpoints', async () => {
await Promise.all([
deepEqual(
strictEqual(
(await aliceClient.request('users/following', { userId: alice.id }))
.some(v => v.followeeId === bobInAServer.object.id),
true,
),
deepEqual(
strictEqual(
(await bobClient.request('users/followers', { userId: bob.id }))
.some(v => v.followerId === aliceInBServer.object.id),
true,
Expand All @@ -112,12 +109,12 @@ describe('User', () => {

test('Check consistency with `users/following` and `users/followers` endpoints', async () => {
await Promise.all([
deepEqual(
strictEqual(
(await aliceClient.request('users/following', { userId: alice.id }))
.some(v => v.followeeId === bobInAServer.object.id),
false,
),
deepEqual(
strictEqual(
(await bobClient.request('users/followers', { userId: bob.id }))
.some(v => v.followerId === aliceInBServer.object.id),
false,
Expand Down

0 comments on commit 28af0f3

Please sign in to comment.