Add iOS popular reads to new iOS users

This commit is contained in:
Hongbo Wu 2022-10-11 16:07:49 +08:00
parent 606183829a
commit af9147d9d3
3 changed files with 38 additions and 8 deletions

View file

@ -126,6 +126,7 @@ export class AddPopularReadsToNewUser
}
async afterInsert(event: InsertEvent<Profile>): Promise<void> {
await addPopularReadsForNewUser(event.entity.user.id)
const isIOSUser = event.entity.user.source === 'APPLE'
await addPopularReadsForNewUser(event.entity.user.id, isIOSUser)
}
}

View file

@ -113,13 +113,15 @@ const addPopularReads = async (
}
export const addPopularReadsForNewUser = async (
userId: string
userId: string,
isIOSUser = false
): Promise<void> => {
await addPopularReads(
userId,
'omnivore_get_started',
'power_read_it_later',
'omnivore_organize'
'omnivore_organize',
isIOSUser ? 'omnivore_ios' : 'omnivore_android'
)
}

View file

@ -569,21 +569,24 @@ describe('auth router', () => {
context('when inputs are valid and user not exists', () => {
let name = 'test_user'
let username = 'test_user'
let sourceUserId = 'test_source_user_id'
let email = 'test_user@omnivore.app'
let bio = 'test_bio'
after(async () => {
afterEach(async () => {
await deleteTestUser(username)
})
it('adds popular reads to the library', async () => {
const pendingUserToken = await createPendingUserToken({
sourceUserId: 'test_source_user_id',
email: 'test_user@omnivore.app',
provider: 'APPLE',
sourceUserId,
email,
provider: 'EMAIL',
name,
username,
})
await createAccountRequest(
'',
bio,
name,
username,
pendingUserToken!
@ -596,6 +599,30 @@ describe('auth router', () => {
expect(count).to.eql(3)
})
it('adds iOS popular reads to the library if provider is iOS', async () => {
const pendingUserToken = await createPendingUserToken({
sourceUserId,
email,
provider: 'APPLE',
name,
username,
})
await createAccountRequest(
bio,
name,
username,
pendingUserToken!
).expect(200)
const user = await getRepository(User).findOneBy({ name })
const [popularReads, count] = (await searchPages({}, user?.id!)) || [
[],
0,
]
// TODO: update this when we have more iOS popular reads
expect(count).to.eql(3)
})
})
})
})