Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 18 additions & 1 deletion src/domain/notification/getRecentAggregated/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Requester } from '^/domain/authentication/types';
import { Range } from '^/domain/common/types';
import validateRange from '^/domain/common/validateRange/feature';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -13,5 +14,21 @@ export default async function feature(requester: Requester, range: Range): Promi

const data = await getRecent(requester.id, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const notifications: AggregatedData[] = [];

const promises = await Promise.allSettled(data.map(item => aggregate(requester, item)));

promises.forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error on aggregating Notification', promise.reason);

return;
}

notifications.push(promise.value);
});

return (notifications);
}
19 changes: 18 additions & 1 deletion src/domain/post/exploreAggregated/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Requester } from '^/domain/authentication/types';
import type { Range } from '^/domain/common/types';
import validateRange from '^/domain/common/validateRange/feature';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -13,5 +14,21 @@ export default async function feature(requester: Requester, range: Range): Promi

const data = await explore(requester, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const posts: AggregatedData[] = [];

const promises = await Promise.allSettled(data.map(item => aggregate(requester, item)));

promises.forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error on aggregating Post', promise.reason);

return;
}

posts.push(promise.value);
});

return posts;
}
19 changes: 18 additions & 1 deletion src/domain/post/getAllAggregated/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Requester } from '^/domain/authentication/types';
import type { Range } from '^/domain/common/types';
import validateRange from '^/domain/common/validateRange/feature';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -13,5 +14,21 @@ export default async function feature(requester: Requester, range: Range): Promi

const data = await getAll(requester, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const posts: AggregatedData[] = [];

const promises = await Promise.allSettled(data.map(item => aggregate(requester, item)));

promises.forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error on aggregating Post', promise.reason);

return;
}

posts.push(promise.value);
});

return posts;
}
20 changes: 19 additions & 1 deletion src/domain/post/getByCreatorAggregated/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Requester } from '^/domain/authentication/types';
import { Range } from '^/domain/common/types';
import validateRange from '^/domain/common/validateRange/feature';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -15,5 +16,22 @@ export default async function feature(requester: Requester, creatorId: string, r

const data = await getByCreator(creatorId, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const posts: AggregatedData[] = [];

const promises = Promise.allSettled(data.map(item => aggregate(requester, item)));

(await promises).forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error on aggregating Post', promise.reason);

return;
}

posts.push(promise.value);

});

return posts;
}
19 changes: 18 additions & 1 deletion src/domain/post/getByFollowingAggregated/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Requester } from '^/domain/authentication/types';
import type { Range } from '^/domain/common/types';
import validateRange from '^/domain/common/validateRange/feature';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -13,5 +14,21 @@ export default async function feature(requester: Requester, range: Range): Promi

const data = await getByFollowing(requester, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const posts: AggregatedData[] = [];

const promises = await Promise.allSettled(data.map(item => aggregate(requester, item)));

promises.forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error aggrgating Post', promise.reason);

return;
}

posts.push(promise.value);
});

return posts;
}
19 changes: 18 additions & 1 deletion src/domain/reaction/getByPostAggregated/feature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import type { Requester } from '^/domain/authentication/types';
import { Range } from '^/domain/common/types';
import logger from '^/integrations/logging/module';

import aggregate from '../aggregate/feature';
import type { AggregatedData } from '../aggregate/types';
Expand All @@ -10,5 +11,21 @@ export default async function feature(requester: Requester, postId: string, rang
{
const data = await getByPost(postId, range.limit, range.offset);

return Promise.all(data.map(item => aggregate(requester, item)));
const reactions: AggregatedData[] = [];

const promises = await Promise.allSettled(data.map(item => aggregate(requester, item)));

promises.forEach((promise) =>
{
if (promise.status === 'rejected')
{
logger.logError('Error on aggregating Reaction', promise.reason);

return;
}

reactions.push(promise.value);
});

return reactions;
}
6 changes: 4 additions & 2 deletions test/domain/notification/fixtures/records.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const RECORDS: Record<string, Array<RecordData>> =

POSTS: [
{ id: VALUES.IDS.POST_RATED, creatorId: REQUESTERS.CREATOR1.id, comicId: VALUES.IDS.COMIC, createdAt: new Date(), ratingCount: 10, reactionCount: 0, deleted: false },
{ id: VALUES.IDS.POST_DELETED, creatorId: REQUESTERS.CREATOR1.id, comicId: VALUES.IDS.COMIC, createdAt: new Date(), ratingCount: 5, reactionCount: 1, deleted: true },
],

REACTIONS: [
Expand All @@ -37,8 +38,9 @@ export const RECORDS: Record<string, Array<RecordData>> =
NOTIFICATIONS: [
{ id: VALUES.IDS.NOTIFICATION1, createdAt: new Date(), type: Types.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR2, postId: undefined, reactionId: undefined },
{ id: VALUES.IDS.NOTIFICATION2, createdAt: new Date(), type: Types.STARTED_FOLLOWING, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: undefined },
{ id: VALUES.IDS.NOTIFICATION3, createdAt: new Date('01-05-2024'), type: Types.RATED_POST, senderId: VALUES.IDS.CREATOR3, receiverId: VALUES.IDS.CREATOR1, postId: VALUES.IDS.POST_RATED, reactionId: undefined },
{ id: VALUES.IDS.NOTIFICATION4, createdAt: new Date('01-04-2024'), type: Types.RATED_REACTION, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: VALUES.IDS.REACTION_LIKED }
{ id: VALUES.IDS.NOTIFICATION3, createdAt: new Date('01-05-2024'), type: Types.RATED_POST, senderId: VALUES.IDS.CREATOR3, receiverId: VALUES.IDS.CREATOR2, postId: VALUES.IDS.POST_RATED, reactionId: undefined },
{ id: VALUES.IDS.NOTIFICATION4, createdAt: new Date('01-04-2024'), type: Types.RATED_REACTION, senderId: VALUES.IDS.CREATOR2, receiverId: VALUES.IDS.CREATOR1, postId: undefined, reactionId: VALUES.IDS.REACTION_LIKED },
{ id: VALUES.IDS.NOTIFICATION5, createdAt: new Date('01-03-2024'), type: Types.RATED_POST, senderId: VALUES.IDS.CREATOR1, receiverId: VALUES.IDS.CREATOR1, postId: VALUES.IDS.POST_DELETED, reactionId: undefined },
],

};
2 changes: 2 additions & 0 deletions test/domain/notification/fixtures/values.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const VALUES =
COMIC: 'C1',
IMAGE: 'I1',
POST_RATED: 'P1',
POST_DELETED: 'P2',

REACTION_LIKED: 'R1',

Expand All @@ -15,6 +16,7 @@ export const VALUES =
NOTIFICATION2: 'N2',
NOTIFICATION3: 'N3',
NOTIFICATION4: 'N4',
NOTIFICATION5: 'N5',

CREATOR1: 'CR1',
CREATOR2: 'CR2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,45 @@ beforeEach(async () =>

describe('domain/notification/getallAggregated', () =>
{
it('should give all posts for the requester', async () =>
it('should give all notifications for the requester2', async () =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should give all notifications for the requester2', async () =>
it('should give all notifications under normal circumstances', async () =>

The specific requester doesn't matter because it's fixture related, and is not a part of what we're testing.

{
const result = await getRecentAggregated(REQUESTERS.CREATOR1, { offset: 0, limit: 7 });
const result = await getRecentAggregated(REQUESTERS.CREATOR2, { offset: 0, limit: 7 });

expect(result).toHaveLength(3);
expect(result).toHaveLength(2);

const notification1 = result[0];
const notification2 = result[1];
const notification3 = result[2];

expect(notification1.type).toBe(Types.STARTED_FOLLOWING);
expect(notification1.post).toBe(undefined);
expect(notification1.reaction).toBe(undefined);
expect(notification1.relation.following.id).toBe(VALUES.IDS.CREATOR2);
expect(notification1.relation.following.id).toBe(VALUES.IDS.CREATOR1);

expect(notification2.type).toBe(Types.RATED_POST);
expect(notification2.post?.id).toBe(VALUES.IDS.POST_RATED);
expect(notification2.reaction).toBe(undefined);
expect(notification2.relation.following.id).toBe(VALUES.IDS.CREATOR3);

expect(notification3.type).toBe(Types.RATED_REACTION);
expect(notification3.post).toBe(undefined);
expect(notification3.reaction?.id).toBe(VALUES.IDS.REACTION_LIKED);
expect(notification3.relation.following.id).toBe(VALUES.IDS.CREATOR2);
});

it('should give only the notifications without aggregation errors for requester1', async () =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should give only the notifications without aggregation errors for requester1', async () =>
it('should filter out deleted notifications without aggregation errors', async () =>

The specific requester doesn't matter because it's fixture related, and is not a part of what we're testing.

{
const result = await getRecentAggregated(REQUESTERS.CREATOR1, { offset: 0, limit: 7 });

expect(result).toHaveLength(2);

const notification1 = result[0];
const notification2 = result[1];

expect(notification1.type).toBe(Types.STARTED_FOLLOWING);
expect(notification1.post).toBe(undefined);
expect(notification1.reaction).toBe(undefined);
expect(notification1.relation.following.id).toBe(VALUES.IDS.CREATOR2);

expect(notification2.type).toBe(Types.RATED_REACTION);
expect(notification2.post).toBe(undefined);
expect(notification2.reaction?.id).toBe(VALUES.IDS.REACTION_LIKED);
expect(notification2.relation.following.id).toBe(VALUES.IDS.CREATOR2);

});
});