From ebc24e4f22cf6a75c89cd18deb8bff18af826252 Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 16:43:15 -0400 Subject: [PATCH 1/7] buyer --- .../mappers/usdcPurchaseBuyer.ts | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts index ef6de3d57da..03bd206c4e3 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts @@ -32,6 +32,7 @@ export class USDCPurchaseBuyer extends BaseNotification { sellerUserId: number amount: string contentId: number + contentType: string extraAmount: string totalAmount: string @@ -41,7 +42,6 @@ export class USDCPurchaseBuyer extends BaseNotification { notification: USDCPurchaseBuyerRow ) { super(dnDB, identityDB, notification) - const userIds: number[] = this.notification.user_ids! this.amount = formatUSDCWeiToUSDString( this.notification.data.amount.toString() ) @@ -56,6 +56,7 @@ export class USDCPurchaseBuyer extends BaseNotification { this.sellerUserId = this.notification.data.seller_user_id this.notificationReceiverUserId = this.notification.data.buyer_user_id this.contentId = this.notification.data.content_id + this.contentType = this.notification.data.content_type } async processNotification({ @@ -78,20 +79,41 @@ export class USDCPurchaseBuyer extends BaseNotification { [this.notificationReceiverUserId, this.sellerUserId] ) - const tracks = await this.fetchEntities([this.contentId], EntityType.Track) - const track = tracks[this.contentId] - if (!('title' in track)) { - logger.error(`Missing title in track ${track}`) - return + let purchasedContentName, cover_art_sizes, slug + if (this.contentType === 'track') { + const tracks = await this.fetchEntities( + [this.contentId], + EntityType.Track + ) + const track = tracks[this.contentId] + if (!('title' in track)) { + logger.error(`Missing title in track ${track}`) + return + } + purchasedContentName = track.title + cover_art_sizes = track.cover_art_sizes + slug = track.slug + } else { + const albums = await this.fetchEntities( + [this.contentId], + EntityType.Album + ) + const album = albums[this.contentId] + if (!('playlist_name' in album)) { + logger.error(`Missing title in album ${album}`) + return + } + purchasedContentName = album.playlist_name + cover_art_sizes = album.cover_art_sizes + slug = album.slug } - const purchasedTrackName = track.title const sellerUsername = users[this.sellerUserId]?.name const sellerHandle = users[this.sellerUserId]?.handle const purchaserUsername = users[this.notificationReceiverUserId]?.name const title = 'Purchase Successful' - const body = `You just purchased ${purchasedTrackName} from ${capitalize( + const body = `You just purchased ${purchasedContentName} from ${capitalize( sellerUsername )}!` await sendBrowserNotification( @@ -171,9 +193,9 @@ export class USDCPurchaseBuyer extends BaseNotification { html: email({ purchaserName: purchaserUsername, artistName: sellerUsername, - trackTitle: purchasedTrackName, - trackLink: `${getHostname()}/${sellerHandle}/${track.slug}`, - trackImage: `${getContentNode()}/content/${track.cover_art_sizes}/480x480.jpg`, + contentTitle: purchasedContentName, + contentLink: `${getHostname()}/${sellerHandle}/${slug}`, + contentImage: `${getContentNode()}/content/${cover_art_sizes}/480x480.jpg`, price: this.amount, payExtra: this.extraAmount, total: this.totalAmount From 7442e4a53a31a185e16ada4dd5e339c78be771d9 Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 16:19:29 -0400 Subject: [PATCH 2/7] WIP --- .../notifications/preRendered/purchase.ts | 18 ++--- .../email/notifications/preRendered/sale.ts | 22 +++--- .../src/processNotifications/mappers/base.ts | 29 +++++-- .../mappers/usdcPurchaseBuyer.ts | 20 +++-- .../mappers/usdcPurchaseSeller.ts | 78 ++++++++++++++----- 5 files changed, 114 insertions(+), 53 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/purchase.ts b/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/purchase.ts index 0c79b0900fa..95ab04cc668 100644 --- a/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/purchase.ts +++ b/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/purchase.ts @@ -1,17 +1,17 @@ export const email = ({ purchaserName, - trackTitle, - trackLink, - trackImage, + contentTitle, + contentLink, + contentImage, artistName, price, payExtra, total }: { purchaserName: string - trackTitle: string - trackLink: string - trackImage: string + contentTitle: string + contentLink: string + contentImage: string artistName: string price: string payExtra: string @@ -169,7 +169,7 @@ export const email = ({
- + @@ -212,7 +212,7 @@ export const email = ({ diff --git a/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/sale.ts b/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/sale.ts index f6252c6c743..fd582bdcc02 100644 --- a/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/sale.ts +++ b/packages/discovery-provider/plugins/notifications/src/email/notifications/preRendered/sale.ts @@ -1,19 +1,19 @@ export const email = ({ purchaserName, - purchaserLink, - trackTitle, - trackLink, - trackImage, + purchaserLink, + contentTitle, + contentLink, + contentImage, artistName, price, payExtra, total }: { purchaserName: string - purchaserLink: string - trackTitle: string - trackLink: string - trackImage: string + purchaserLink: string + contentTitle: string + contentLink: string + contentImage: string artistName: string price: string payExtra: string @@ -171,7 +171,7 @@ export const email = ({
@@ -183,7 +183,7 @@ export const email = ({
- +
- ${trackTitle}
${artistName}
+ ${contentTitle}
${artistName}
- + @@ -214,7 +214,7 @@ export const email = ({ diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts index b74ebd95203..b2cf506d645 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts @@ -14,6 +14,8 @@ type PlaylistInfo = { playlist_id: number playlist_name: string is_album: boolean + playlist_image_sizes_multihash: string + slug: string } type TrackInfo = { @@ -40,14 +42,17 @@ export abstract class BaseNotification { const res: Array<{ track_id: number title: string - cover_art_sizes:string + cover_art_sizes: string slug: string }> = await this.dnDB - .select('tracks.track_id', 'tracks.title', 'tracks.cover_art_sizes', 'track_routes.slug') + .select( + 'tracks.track_id', + 'tracks.title', + 'tracks.cover_art_sizes', + 'track_routes.slug' + ) .from('tracks') .join('track_routes', 'tracks.track_id', 'track_routes.track_id') - .where('track_routes.is_current', true) - .where('tracks.is_current', true) .whereIn( 'tracks.track_id', entityIds.map((id) => id.toString()) @@ -66,10 +71,22 @@ export abstract class BaseNotification { playlist_id: number playlist_name: string is_album: boolean + playlist_image_sizes_multihash: string + slug: string }> = await this.dnDB - .select('playlist_id', 'playlist_name', 'is_album') + .select( + 'playlist_id', + 'playlist_name', + 'is_album', + 'playlist_image_sizes_multihash', + 'slug' + ) .from('playlists') - .where('is_current', true) + .join( + 'playlist_routes', + 'playlists.playlist_id', + 'playlist_routes.playlist_id' + ) .whereIn( 'playlist_id', entityIds.map((id) => id.toString()) diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts index 03bd206c4e3..01fc703b746 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts @@ -104,7 +104,7 @@ export class USDCPurchaseBuyer extends BaseNotification { return } purchasedContentName = album.playlist_name - cover_art_sizes = album.cover_art_sizes + cover_art_sizes = album.playlist_image_sizes_multihash slug = album.slug } @@ -206,20 +206,28 @@ export class USDCPurchaseBuyer extends BaseNotification { getResourcesForEmail(): ResourceIds { const tracks = new Set() - tracks.add(this.contentId) + const albums = new Set() + if (this.contentType === 'track') { + tracks.add(this.contentId) + } else { + albums.add(this.contentId) + } return { users: new Set([this.notificationReceiverUserId, this.sellerUserId]), - tracks + tracks, + playlists: albums } } formatEmailProps(resources: Resources) { const user = resources.users[this.sellerUserId] const track = resources.tracks[this.contentId] + const album = resources.playlists[this.contentId] + const isTrack = this.contentType === 'track' const entity = { - type: EntityType.Track, - name: track.title, - imageUrl: track.imageUrl + type: isTrack ? EntityType.Track : EntityType.Album, + name: isTrack ? track.title : album.playlist_name, + imageUrl: isTrack ? track.imageUrl : album.imageUrl } return { type: this.notification.type, diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts index bce98c9d079..0afbb4bc90e 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts @@ -28,20 +28,21 @@ type USDCPurchaseSellerRow = Omit & { data: USDCPurchaseSellerNotification } -const title = 'Track Sold' const body = ( buyerUsername: string, - purchasedTrackName: string, + purchasedContentName: string, + contentType: string, price: string ): string => `Congrats, ${capitalize( buyerUsername - )} just bought your track ${purchasedTrackName} for $${price}!` + )} just bought your ${contentType} ${purchasedContentName} for $${price}!` export class USDCPurchaseSeller extends BaseNotification { notificationReceiverUserId: number buyerUserId: number amount: string contentId: number + contentType: string extraAmount: string totalAmount: string @@ -65,6 +66,7 @@ export class USDCPurchaseSeller extends BaseNotification this.buyerUserId = this.notification.data.buyer_user_id this.notificationReceiverUserId = this.notification.data.seller_user_id this.contentId = this.notification.data.content_id + this.contentType = this.notification.data.content_type } async processNotification({ @@ -87,14 +89,37 @@ export class USDCPurchaseSeller extends BaseNotification [this.notificationReceiverUserId, this.buyerUserId] ) - const tracks = await this.fetchEntities([this.contentId], EntityType.Track) - const track = tracks[this.contentId] - if (!('title' in track)) { - logger.error(`Missing title in track ${track}`) - return + let purchasedContentName, cover_art_sizes, slug, title + if (this.contentType === 'track') { + const tracks = await this.fetchEntities( + [this.contentId], + EntityType.Track + ) + const track = tracks[this.contentId] + if (!('title' in track)) { + logger.error(`Missing title in track ${track}`) + return + } + title = 'Track Sold' + purchasedContentName = track.title + cover_art_sizes = track.cover_art_sizes + slug = track.slug + } else { + const albums = await this.fetchEntities( + [this.contentId], + EntityType.Album + ) + const album = albums[this.contentId] + if (!('playlist_name' in album)) { + logger.error(`Missing title in album ${album}`) + return + } + title = 'Album sold' + purchasedContentName = album.playlist_name + cover_art_sizes = album.playlist_image_sizes_multihash + slug = album.slug } - const purchasedTrackName = track.title const buyerUsername = users[this.buyerUserId]?.name const buyerHandle = users[this.buyerUserId]?.handle const sellerUsername = users[this.notificationReceiverUserId]?.name @@ -106,7 +131,7 @@ export class USDCPurchaseSeller extends BaseNotification userNotificationSettings, this.notificationReceiverUserId, title, - body(buyerUsername, purchasedTrackName, price) + body(buyerUsername, purchasedContentName, this.contentType, price) ) if ( userNotificationSettings.shouldSendPushNotification({ @@ -130,7 +155,12 @@ export class USDCPurchaseSeller extends BaseNotification }, { title, - body: body(buyerUsername, purchasedTrackName, price), + body: body( + buyerUsername, + purchasedContentName, + this.contentType, + price + ), data: { id: `timestamp:${this.getNotificationTimestamp()}:group_id:${ this.notification.group_id @@ -178,11 +208,9 @@ export class USDCPurchaseSeller extends BaseNotification purchaserName: buyerUsername, purchaserLink: `${getHostname()}/${buyerHandle}`, artistName: sellerUsername, - trackTitle: purchasedTrackName, - trackLink: `${getHostname()}/${sellerHandle}/${track.slug}`, - trackImage: `${getContentNode()}/content/${ - track.cover_art_sizes - }/480x480.jpg`, + contentTitle: purchasedContentName, + contentLink: `${getHostname()}/${sellerHandle}/${slug}`, + contentImage: `${getContentNode()}/content/${cover_art_sizes}/480x480.jpg`, price: this.amount, payExtra: this.extraAmount, total: this.totalAmount @@ -193,20 +221,28 @@ export class USDCPurchaseSeller extends BaseNotification getResourcesForEmail(): ResourceIds { const tracks = new Set() - tracks.add(this.contentId) + const albums = new Set() + if (this.contentType === 'track') { + tracks.add(this.contentId) + } else { + albums.add(this.contentId) + } return { users: new Set([this.notificationReceiverUserId, this.buyerUserId]), - tracks + tracks, + playlists: albums } } formatEmailProps(resources: Resources) { const user = resources.users[this.buyerUserId] const track = resources.tracks[this.contentId] + const album = resources.playlists[this.contentId] + const isTrack = this.contentType === 'track' const entity = { - type: EntityType.Track, - name: track.title, - imageUrl: track.imageUrl + type: isTrack ? EntityType.Track : EntityType.Album, + name: isTrack ? track.title : album.playlist_name, + imageUrl: isTrack ? track.imageUrl : album.imageUrl } return { type: this.notification.type, From a7442ef1229d6d9cbf297dbc43412a9228fcda7f Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 17:28:56 -0400 Subject: [PATCH 3/7] [PAY-2692] Purchase/sale push+email notification album support --- .../usdcPurchaseBuyer.test.ts.snap | 10 +- .../usdcPurchaseSeller.test.ts.snap | 1204 ++++++++++++++++- .../mappings/usdcPurchaseBuyer.test.ts | 60 +- .../mappings/usdcPurchaseSeller.test.ts | 56 +- .../notifications/src/utils/populateDB.ts | 4 +- 5 files changed, 1307 insertions(+), 27 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseBuyer.test.ts.snap b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseBuyer.test.ts.snap index 6c7e3584029..36805976dda 100644 --- a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseBuyer.test.ts.snap +++ b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseBuyer.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`USDC Purchase Buyer Render a single email 1`] = ` +exports[`USDC Purchase Buyer Render emails 1`] = ` "
2024 Audius, Inc. All Rights Reserved.
@@ -185,7 +185,7 @@ export const email = ({
- +
- ${trackTitle}
${artistName}
+ ${contentTitle}
${artistName}
Tired of seeing these emails? Update your notification preferences
" +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

You just purchased track_title_10 from user_1!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" `; -exports[`USDC Purchase Buyer Render a single email 1`] = ` +exports[`USDC Purchase Buyer Render emails 2`] = ` "
2024 Audius, Inc. All Rights Reserved.
" +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

You just purchased playlist_name_15 from user_1!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" `; diff --git a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap index 350465a001a..5f353bc5bef 100644 --- a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap +++ b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap @@ -595,10 +595,1206 @@ exports[`USDC Purchase Seller Render a single email 1`] = ` ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ -

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track track_title_10 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track track_title_10 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" +`; + +exports[`USDC Purchase Seller Render a single email 2`] = ` +"
+ +
Daily Email - joey@audius.co

Congrats, user_2 just bought your track playlist_name_15 for $1.00! + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track playlist_name_15 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" +`; + +exports[`USDC Purchase Seller Render emails 1`] = ` +"
+ +
Daily Email - joey@audius.co

Congrats, user_2 just bought your track track_title_10 for $1.00! + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + + ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track track_title_10 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" `; -exports[`USDC Purchase Seller Render a single email 1`] = ` +exports[`USDC Purchase Seller Render emails 2`] = ` "
2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" +

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track playlist_name_15 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" `; diff --git a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseBuyer.test.ts b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseBuyer.test.ts index 91cfd88c116..112cb53f6f2 100644 --- a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseBuyer.test.ts +++ b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseBuyer.test.ts @@ -12,7 +12,8 @@ import { setupTest, resetTests, setUserEmailAndSettings, - createUSDCPurchase + createUSDCPurchase, + createPlaylists } from '../../utils/populateDB' import { AppEmailNotification } from '../../types/notifications' @@ -116,21 +117,32 @@ describe('USDC Purchase Buyer', () => { }) }) - test('Render a single email', async () => { + test('Render emails', async () => { await createUsers(processor.discoveryDB, [{ user_id: 1 }, { user_id: 2 }]) await createTracks(processor.discoveryDB, [{ track_id: 10, owner_id: 1 }]) + await createPlaylists(processor.discoveryDB, [ + { playlist_id: 15, playlist_owner_id: 1 } + ]) await createUSDCPurchase(processor.discoveryDB, [ { seller_user_id: 1, buyer_user_id: 2, content_type: usdc_purchase_content_type.track, content_id: 10, - amount: '1000', + amount: '1000000', + extra_amount: '0' + }, + { + seller_user_id: 1, + buyer_user_id: 2, + content_type: usdc_purchase_content_type.album, + content_id: 15, + amount: '1000000', extra_amount: '0' } ]) - const notifications: AppEmailNotification[] = [ + const trackNotifications: AppEmailNotification[] = [ { type: 'usdc_purchase_buyer', timestamp: new Date(), @@ -140,22 +152,52 @@ describe('USDC Purchase Buyer', () => { data: { buyer_user_id: 2, seller_user_id: 1, - amount: 1000, + amount: 1000000, + extra_amount: 0, + content_id: 10, + content_type: 'track' + }, + user_ids: [2], + receiver_user_id: 2 + } + ] + const trackNotificationHtml = await renderEmail({ + userId: 2, + email: 'joey@audius.co', + frequency: 'daily', + notifications: trackNotifications, + dnDb: processor.discoveryDB, + identityDb: processor.identityDB + }) + expect(trackNotificationHtml).toMatchSnapshot() + + const albumNotifications: AppEmailNotification[] = [ + { + type: 'usdc_purchase_buyer', + timestamp: new Date(), + specifier: '2', + group_id: + 'usdc_purchase_buyer:seller_user_id:1:buyer_user_id:2:content_id:15:content_type:album', + data: { + buyer_user_id: 2, + seller_user_id: 1, + amount: 1000000, extra_amount: 0, - content_id: 10 + content_id: 15, + content_type: 'album' }, user_ids: [2], receiver_user_id: 2 } ] - const notifHtml = await renderEmail({ + const albumNotificationHtml = await renderEmail({ userId: 2, email: 'joey@audius.co', frequency: 'daily', - notifications, + notifications: albumNotifications, dnDb: processor.discoveryDB, identityDb: processor.identityDB }) - expect(notifHtml).toMatchSnapshot() + expect(albumNotificationHtml).toMatchSnapshot() }) }) diff --git a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseSeller.test.ts b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseSeller.test.ts index d5e490159cb..850c77633d0 100644 --- a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseSeller.test.ts +++ b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/usdcPurchaseSeller.test.ts @@ -12,7 +12,8 @@ import { setupTest, resetTests, setUserEmailAndSettings, - createUSDCPurchase + createUSDCPurchase, + createPlaylists } from '../../utils/populateDB' import { AppEmailNotification } from '../../types/notifications' @@ -117,9 +118,12 @@ describe('USDC Purchase Seller', () => { }) }) - test('Render a single email', async () => { + test('Render emails', async () => { await createUsers(processor.discoveryDB, [{ user_id: 1 }, { user_id: 2 }]) await createTracks(processor.discoveryDB, [{ track_id: 10, owner_id: 1 }]) + await createPlaylists(processor.discoveryDB, [ + { playlist_id: 15, playlist_owner_id: 1 } + ]) await createUSDCPurchase(processor.discoveryDB, [ { seller_user_id: 1, @@ -128,10 +132,18 @@ describe('USDC Purchase Seller', () => { content_id: 10, amount: '1000000', extra_amount: '0' + }, + { + seller_user_id: 1, + buyer_user_id: 2, + content_type: usdc_purchase_content_type.album, + content_id: 15, + amount: '1000000', + extra_amount: '0' } ]) - const notifications: AppEmailNotification[] = [ + const trackNotifications: AppEmailNotification[] = [ { type: 'usdc_purchase_seller', timestamp: new Date(), @@ -143,20 +155,50 @@ describe('USDC Purchase Seller', () => { seller_user_id: 1, amount: 1000000, extra_amount: 0, - content_id: 10 + content_id: 10, + content_type: 'track' + }, + user_ids: [1], + receiver_user_id: 1 + } + ] + const trackNotificationHtml = await renderEmail({ + userId: 1, + email: 'joey@audius.co', + frequency: 'daily', + notifications: trackNotifications, + dnDb: processor.discoveryDB, + identityDb: processor.identityDB + }) + expect(trackNotificationHtml).toMatchSnapshot() + + const albumNotifications: AppEmailNotification[] = [ + { + type: 'usdc_purchase_seller', + timestamp: new Date(), + specifier: '2', + group_id: + 'usdc_purchase_seller:seller_user_id:1:buyer_user_id:2:content_id:15:content_type:album', + data: { + buyer_user_id: 2, + seller_user_id: 1, + amount: 1000000, + extra_amount: 0, + content_id: 15, + content_type: 'album' }, user_ids: [1], receiver_user_id: 1 } ] - const notifHtml = await renderEmail({ + const albumNotificationHtml = await renderEmail({ userId: 1, email: 'joey@audius.co', frequency: 'daily', - notifications, + notifications: albumNotifications, dnDb: processor.discoveryDB, identityDb: processor.identityDB }) - expect(notifHtml).toMatchSnapshot() + expect(albumNotificationHtml).toMatchSnapshot() }) }) diff --git a/packages/discovery-provider/plugins/notifications/src/utils/populateDB.ts b/packages/discovery-provider/plugins/notifications/src/utils/populateDB.ts index 152d1560b55..29a357d4202 100644 --- a/packages/discovery-provider/plugins/notifications/src/utils/populateDB.ts +++ b/packages/discovery-provider/plugins/notifications/src/utils/populateDB.ts @@ -347,9 +347,9 @@ export const createUSDCPurchase = async ( ) => { await db .insert( - usdcPurchases.map((usdcPurchase) => ({ + usdcPurchases.map((usdcPurchase, index) => ({ created_at: new Date(Date.now()), - slot: '4', + slot: index, signature: 'fake_signature', ...usdcPurchase })) From 65c18af3a0eab1b2e3b7ae8bfb2913c6ed3f8c8e Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 18:00:04 -0400 Subject: [PATCH 4/7] update slug --- .../src/processNotifications/mappers/usdcPurchaseBuyer.ts | 2 +- .../src/processNotifications/mappers/usdcPurchaseSeller.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts index 01fc703b746..b3a7dc3c452 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseBuyer.ts @@ -105,7 +105,7 @@ export class USDCPurchaseBuyer extends BaseNotification { } purchasedContentName = album.playlist_name cover_art_sizes = album.playlist_image_sizes_multihash - slug = album.slug + slug = `album/${album.slug}` } const sellerUsername = users[this.sellerUserId]?.name diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts index 0afbb4bc90e..64159b37419 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/usdcPurchaseSeller.ts @@ -117,7 +117,7 @@ export class USDCPurchaseSeller extends BaseNotification title = 'Album sold' purchasedContentName = album.playlist_name cover_art_sizes = album.playlist_image_sizes_multihash - slug = album.slug + slug = `album/${album.slug}` } const buyerUsername = users[this.buyerUserId]?.name From cd6bdd5b9d77cefcaef933937ce4421dd581f5c7 Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 18:28:20 -0400 Subject: [PATCH 5/7] fix ambiguous key fetch --- .../src/processNotifications/mappers/base.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts index b2cf506d645..9546ca1dd1d 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts @@ -75,11 +75,11 @@ export abstract class BaseNotification { slug: string }> = await this.dnDB .select( - 'playlist_id', - 'playlist_name', - 'is_album', - 'playlist_image_sizes_multihash', - 'slug' + 'playlists.playlist_id', + 'playlists.playlist_name', + 'playlists.is_album', + 'playlists.playlist_image_sizes_multihash', + 'playlist_routes.slug' ) .from('playlists') .join( From 9359b77a53dd1cdadddaefcd46cd692a7ac2e348 Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 18:32:53 -0400 Subject: [PATCH 6/7] fix 1 more ambiguous --- .../notifications/src/processNotifications/mappers/base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts index 9546ca1dd1d..bc9e1dfc256 100644 --- a/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts +++ b/packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/base.ts @@ -88,7 +88,7 @@ export abstract class BaseNotification { 'playlist_routes.playlist_id' ) .whereIn( - 'playlist_id', + 'playlists.playlist_id', entityIds.map((id) => id.toString()) ) return res.reduce>( From c81dbd66dab1257f91874d73ef2e6869b88967cc Mon Sep 17 00:00:00 2001 From: Dharit Tantiviramanond Date: Thu, 18 Apr 2024 18:37:43 -0400 Subject: [PATCH 7/7] update seller snapshot --- .../usdcPurchaseSeller.test.ts.snap | 1196 ----------------- 1 file changed, 1196 deletions(-) diff --git a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap index 5f353bc5bef..2ce8f48e6c8 100644 --- a/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap +++ b/packages/discovery-provider/plugins/notifications/src/__tests__/mappings/__snapshots__/usdcPurchaseSeller.test.ts.snap @@ -1,1201 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`USDC Purchase Seller Render a single email 1`] = ` -"
- -
Daily Email - joey@audius.co

Congrats, user_2 just bought your track track_title_10 for $1.00! - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ -

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track track_title_10 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" -`; - -exports[`USDC Purchase Seller Render a single email 2`] = ` -"
- -
Daily Email - joey@audius.co

Congrats, user_2 just bought your track playlist_name_15 for $1.00! - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ - - ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ -

Audius Logo
What You Missed

1 unread notification from May 13th 2020

Congrats, user_2 just bought your track playlist_name_15 for $1.00!
Open AudiusArrow Right
See more on Audius
instagramtwitterdiscord
Made with ♥︎ in SF & LA
© 2024 Audius, Inc. All Rights Reserved.
Tired of seeing these emails? Update your notification preferences
" -`; - exports[`USDC Purchase Seller Render emails 1`] = ` "