Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more tests #32

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/__tests__/ActivityPub.jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ActivityPub } from '../ActivityPub';

describe('Tests for ActivityPubClient', () => {
test('Initial state', () => {
expect(ActivityPub.account).toBe(undefined);
});
});
68 changes: 53 additions & 15 deletions lib/__tests__/account.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ import 'node-fetch';

jest.mock('node-fetch', () => jest.fn());

describe('Tests for getInboxIndex', () => {
const getInboxIndex = () => {
const inboxIndexPath = 'lib/__tests__/files/inboxIndex.json';
const inboxIndex = readJSONDictionary(inboxIndexPath, {});
return inboxIndex;
};

test('Check successful', () => {
const expectedInboxIndex = { id: 'inboxIndex' };
expect(getInboxIndex()).toStrictEqual(expectedInboxIndex);
});
});

describe('Tests for writeInboxIndex', () => {
const inboxIndexPath = 'lib/__tests__/files/writeInboxIndex.json';
const writeInboxIndex = data => {
writeJSONDictionary(inboxIndexPath, data);
};

test('Check successful', () => {
const expectedInboxIndex = { id: 'inboxIndex' };
writeInboxIndex(expectedInboxIndex);
const jsonRaw = fs.readFileSync(inboxIndexPath);
expect(JSON.parse(jsonRaw)).toStrictEqual(expectedInboxIndex);
});
});

describe('Tests for isMyPost', () => {
test('Check if a post is my post', () => {
const { DOMAIN } = process.env;
Expand All @@ -25,30 +52,41 @@ describe('Tests for isMyPost', () => {
});
});

describe('Tests for getInboxIndex', () => {
const getInboxIndex = () => {
const inboxIndexPath = 'lib/__tests__/files/inboxIndex.json';
const inboxIndex = readJSONDictionary(inboxIndexPath, {});
return inboxIndex;
describe('Tests for getNotifications', () => {
const notificationsFile = 'lib/__tests__/files/notifications.json';
const getNotifications = () => {
return readJSONDictionary(notificationsFile);
};

test('Check successful', () => {
const expectedInboxIndex = { id: 'inboxIndex' };
expect(getInboxIndex()).toStrictEqual(expectedInboxIndex);
const expectedNotifications = { id: 'notifications' };
expect(getNotifications()).toStrictEqual(expectedNotifications);
});
});

describe('Tests for writeInboxIndex', () => {
const inboxIndexPath = 'lib/__tests__/files/writeInboxIndex.json';
const writeInboxIndex = data => {
writeJSONDictionary(inboxIndexPath, data);
describe('Tests for writeBoosts', () => {
const boostsFile = 'lib/__tests__/files/writeBoosts.json';
const writeBoosts = data => {
return writeJSONDictionary(boostsFile, data);
};

test('Check successful', () => {
const expectedInboxIndex = { id: 'inboxIndex' };
writeInboxIndex(expectedInboxIndex);
const jsonRaw = fs.readFileSync(inboxIndexPath);
expect(JSON.parse(jsonRaw)).toStrictEqual(expectedInboxIndex);
const expectedBoosts = { id: 'boosts' };
writeBoosts(expectedBoosts);
const jsonRaw = fs.readFileSync(boostsFile);
expect(JSON.parse(jsonRaw)).toStrictEqual(expectedBoosts);
});
});

describe('Tests for getBoosts', () => {
const boostsFile = 'lib/__tests__/files/boosts.json';
const getBoosts = () => {
return readJSONDictionary(boostsFile, []);
};

test('Check successful', () => {
const expectedBoosts = { id: 'boosts' };
expect(getBoosts()).toStrictEqual(expectedBoosts);
});
});

Expand Down
3 changes: 3 additions & 0 deletions lib/__tests__/files/boosts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "boosts"
}
3 changes: 3 additions & 0 deletions lib/__tests__/files/notifications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "notifications"
}
3 changes: 3 additions & 0 deletions lib/__tests__/files/writeBoosts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "boosts"
}
3 changes: 3 additions & 0 deletions lib/__tests__/users.jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Tests for fetchUser', () => {
test('Initial state', () => {});
});
Loading