Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { expect, jest, test } from '@jest/globals'
import { Processor } from '../../main'
import * as sns from '../../sns'
import * as web from '../../web'

import {
createTracks,
createUsers,
insertMobileDevices,
insertMobileSettings,
insertNotifications,
resetTests,
setUserEmailAndSettings,
setupTest
} from '../../utils/populateDB'

describe('Track Collaborator Accept', () => {
let processor: Processor

const sendPushNotificationSpy = jest
.spyOn(sns, 'sendPushNotification')
.mockImplementation(() => Promise.resolve({ endpointDisabled: false }))

const sendBrowserNotificationSpy = jest
.spyOn(web, 'sendBrowserNotification')
.mockImplementation(() => Promise.resolve(3))

beforeEach(async () => {
const setup = await setupTest()
processor = setup.processor
})

afterEach(async () => {
await resetTests(processor)
})

test('Process push notification for track collaborator accept', async () => {
// user 1 = collaborator (accepted), user 2 = inviter / track owner (recipient)
await createUsers(processor.discoveryDB, [{ user_id: 1 }, { user_id: 2 }])
await createTracks(processor.discoveryDB, [
{ track_id: 10, owner_id: 2 }
])
await setUserEmailAndSettings(processor.identityDB, 'live', 2)

await insertNotifications(processor.discoveryDB, [
{
id: 1,
specifier: '1',
group_id:
'track_collaborator_accept:track_id:10:collaborator_user_id:1:inviter_user_id:2',
type: 'track_collaborator_accept',
data: {
track_id: 10,
collaborator_user_id: 1,
inviter_user_id: 2
},
user_ids: [2]
}
])

await insertMobileSettings(processor.identityDB, [{ userId: 2 }])
await insertMobileDevices(processor.identityDB, [{ userId: 2 }])

const pending = processor.listener.takePending()
expect(pending?.appNotifications).toHaveLength(1)

const title = 'Collaboration Accepted'
const body =
'user_1 accepted your invitation to collaborate on track_title_10.'
await processor.appNotificationsProcessor.process(pending.appNotifications)

expect(sendPushNotificationSpy).toHaveBeenCalledWith(
{
type: 'ios',
targetARN: 'arn:2',
badgeCount: 1
},
expect.objectContaining({
title,
body,
data: expect.objectContaining({
type: 'TrackCollaboratorAccept',
entityId: 10
})
})
)

expect(sendBrowserNotificationSpy).toHaveBeenCalledWith(
true,
expect.any(Object),
2,
title,
body
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { expect, jest, test } from '@jest/globals'
import { Processor } from '../../main'
import * as sns from '../../sns'
import * as web from '../../web'

import {
createTracks,
createUsers,
insertMobileDevices,
insertMobileSettings,
insertNotifications,
resetTests,
setUserEmailAndSettings,
setupTest
} from '../../utils/populateDB'

describe('Track Collaborator Invite', () => {
let processor: Processor

const sendPushNotificationSpy = jest
.spyOn(sns, 'sendPushNotification')
.mockImplementation(() => Promise.resolve({ endpointDisabled: false }))

const sendBrowserNotificationSpy = jest
.spyOn(web, 'sendBrowserNotification')
.mockImplementation(() => Promise.resolve(3))

beforeEach(async () => {
const setup = await setupTest()
processor = setup.processor
})

afterEach(async () => {
await resetTests(processor)
})

test('Process push notification for track collaborator invite', async () => {
// user 1 = invited collaborator (recipient), user 2 = inviter / track owner
await createUsers(processor.discoveryDB, [{ user_id: 1 }, { user_id: 2 }])
await createTracks(processor.discoveryDB, [
{ track_id: 10, owner_id: 2 }
])
await setUserEmailAndSettings(processor.identityDB, 'live', 1)

await insertNotifications(processor.discoveryDB, [
{
id: 1,
specifier: '2',
group_id:
'track_collaborator_invite:track_id:10:collaborator_user_id:1:inviter_user_id:2',
type: 'track_collaborator_invite',
data: {
track_id: 10,
collaborator_user_id: 1,
inviter_user_id: 2
},
user_ids: [1]
}
])

await insertMobileSettings(processor.identityDB, [{ userId: 1 }])
await insertMobileDevices(processor.identityDB, [{ userId: 1 }])

const pending = processor.listener.takePending()
expect(pending?.appNotifications).toHaveLength(1)

const title = 'Track Collaboration Invite'
const body = 'user_2 invited you to collaborate on track_title_10.'
await processor.appNotificationsProcessor.process(pending.appNotifications)

expect(sendPushNotificationSpy).toHaveBeenCalledWith(
{
type: 'ios',
targetARN: 'arn:1',
badgeCount: 1
},
expect.objectContaining({
title,
body,
data: expect.objectContaining({
type: 'TrackCollaboratorInvite',
entityId: 10
})
})
)

expect(sendBrowserNotificationSpy).toHaveBeenCalledWith(
true,
expect.any(Object),
1,
title,
body
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ const snippetMap = {
const { users } = notification
return `${users[0].name} has been added as a manager on your account.`
},
['track_collaborator_invite'](notification) {
const { users } = notification
return `${users[0].name} invited you to collaborate on a track.`
},
['track_collaborator_accept'](notification) {
const { users } = notification
return `${users[0].name} accepted your invitation to collaborate.`
},
['create'](notification) {
const [user] = notification.users
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ const notificationMap = {
</span>
)
},
['track_collaborator_invite'](notification) {
const [user] = notification.users
return (
<span className={'notificationText'}>
<BodyText
text={`${user.name} invited you to collaborate on a track.`}
/>
</span>
)
},
['track_collaborator_accept'](notification) {
const [user] = notification.users
return (
<span className={'notificationText'}>
<BodyText
text={`${user.name} accepted your invitation to collaborate.`}
/>
</span>
)
},
['create'](notification) {
const [user] = notification.users
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
TrackAddedToPurchasedAlbumNotification,
RequestManagerNotification,
ApproveManagerNotification,
TrackCollaboratorInviteNotification,
TrackCollaboratorAcceptNotification,
ClaimableRewardNotification,
RewardInCooldownNotification,
CommentNotification,
Expand Down Expand Up @@ -81,6 +83,8 @@ import { USDCPurchaseBuyer } from './usdcPurchaseBuyer'
import { USDCWithdrawal } from './usdcWithdrawal'
import { USDCTransfer } from './usdcTransfer'
import { RequestManager } from './requestManager'
import { TrackCollaboratorInvite } from './trackCollaboratorInvite'
import { TrackCollaboratorAccept } from './trackCollaboratorAccept'
import { TrackAddedToPurchasedAlbum } from './trackAddedToPurchasedAlbum'
import { RewardInCooldown } from './rewardInCooldown'
import { ClaimableReward } from './claimableReward'
Expand Down Expand Up @@ -283,6 +287,24 @@ const mapNotification = (
identityDb,
approveManagerNotification
)
} else if (notification.type === 'track_collaborator_invite') {
const trackCollaboratorInviteNotification = notification as NotificationRow & {
data: TrackCollaboratorInviteNotification
}
return new TrackCollaboratorInvite(
dnDb,
identityDb,
trackCollaboratorInviteNotification
)
} else if (notification.type === 'track_collaborator_accept') {
const trackCollaboratorAcceptNotification = notification as NotificationRow & {
data: TrackCollaboratorAcceptNotification
}
return new TrackCollaboratorAccept(
dnDb,
identityDb,
trackCollaboratorAcceptNotification
)
} else if (notification.type === 'claimable_reward') {
const challengeCooldownCompleteNotification =
notification as NotificationRow & {
Expand Down
Loading
Loading