Fix typo with RSS typed subscription queries

This commit is contained in:
Jackson Harper 2023-08-30 14:18:39 +08:00
parent 85d5361d89
commit 79cea907a3
2 changed files with 77 additions and 1 deletions

View file

@ -83,7 +83,7 @@ export const subscriptionsResolver = authorized<
status: SubscriptionStatus.Active,
})
} else if (type && type == SubscriptionType.Rss) {
queryBuilder.where({
queryBuilder.andWhere({
type,
})
} else {

View file

@ -185,6 +185,82 @@ describe('Subscriptions API', () => {
}
})
it('should not return other users subscriptions when type is set to RSS', async () => {
query = `
query {
subscriptions(type: RSS) {
... on SubscriptionsSuccess {
subscriptions {
id
name
}
}
... on SubscriptionsError {
errorCodes
}
}
}
`
const user2 = await createTestUser('fakeUser2')
try {
await createTestSubscription(
user2,
'sub_other',
undefined,
SubscriptionStatus.Unsubscribed,
undefined,
SubscriptionType.Rss
)
const res = await graphqlRequest(query, authToken).expect(200)
expect(res.body.data.subscriptions.subscriptions).to.eql(
subscriptions.map((sub) => ({
id: sub.id,
name: sub.name,
}))
)
} finally {
deleteTestUser(user2.id)
}
})
it('should not return other users subscriptions when type is set to NEWSLETTER', async () => {
query = `
query {
subscriptions(type: NEWSLETTER) {
... on SubscriptionsSuccess {
subscriptions {
id
name
}
}
... on SubscriptionsError {
errorCodes
}
}
}
`
const user2 = await createTestUser('fakeUser2')
try {
await createTestSubscription(
user2,
'sub_other',
undefined,
SubscriptionStatus.Unsubscribed,
undefined,
SubscriptionType.Rss
)
const res = await graphqlRequest(query, authToken).expect(200)
expect(res.body.data.subscriptions.subscriptions).to.eql(
subscriptions.map((sub) => ({
id: sub.id,
name: sub.name,
}))
)
} finally {
deleteTestUser(user2.id)
}
})
it('responds status code 400 when invalid query', async () => {
const invalidQuery = `
query {