Skip to content

Commit

Permalink
Test proposal discussion role notifications
Browse files Browse the repository at this point in the history
(not essential but still nice to have IMO)
  • Loading branch information
thesan committed May 17, 2024
1 parent 64ec54b commit b7d7aae
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions packages/server/test/notifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,66 @@ describe('Notifier', () => {
})
)
})

it('Role notifications', async () => {
// -------------------
// Initialize database
// -------------------

const alice = await createMember(1, 'alice')
const bob = await createMember(2, 'bob')

// -------------------
// Mock QN responses
// -------------------

mockRequest
.mockReturnValueOnce({
workers: [{ groupId: 'forumWorkingGroup', isLead: true, membershipId: alice.id.toString() }],
electedCouncils: [{ councilMembers: [{ memberId: bob.id.toString() }] }],
})
.mockReturnValueOnce({
events: [
proposalDiscussionPostCreatedEvent(1, {
text: 'Hello [@Forum Lead](#mention?role=lead_forumWorkingGroup)',
}),
proposalDiscussionPostCreatedEvent(2, { text: 'Hello [@Council](#mention?role=council)' }),
proposalDiscussionPostCreatedEvent(3, { author: alice.id, text: 'Hello [@Dao](#mention?role=dao)' }),
],
})
.mockReturnValue({
events: [],
proposalDiscussionPostByUniqueInput: {
author: { handle: 'proposal:title' },
discussionThread: {
proposal: { id: 'proposal:id', title: 'proposal:title' },
},
},
})

// -------------------
// Run
// -------------------

await run()

// -------------------
// Check notifications
// -------------------

const notifications = await prisma.notification.findMany()

// Post 1 notify forum lead
expect(notifications).toContainEqual(expect.objectContaining({ entityId: 'post:1', memberId: alice.id }))

// Post 2 notify councilors
expect(notifications).toContainEqual(expect.objectContaining({ entityId: 'post:2', memberId: bob.id }))

// Post 3 notify DAO (except for Alice who posted the thread)
expect(notifications).toContainEqual(expect.objectContaining({ entityId: 'post:3', memberId: bob.id }))

expect(notifications).toHaveLength(3)
})
})
})

Expand Down

0 comments on commit b7d7aae

Please sign in to comment.