Only filter inactive newsletters out from the subscriptions response

This commit is contained in:
Jackson Harper 2023-08-29 11:34:55 +08:00
parent 3925a7bfeb
commit 89c17fd0ab
2 changed files with 38 additions and 5 deletions

View file

@ -74,8 +74,17 @@ export const subscriptionsResolver = authorized<
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
.where({
user: { id: uid },
})
// Show all RSS, but only active newsletters
queryBuilder
.where({
type: SubscriptionType.Newsletter,
status: SubscriptionStatus.Active,
})
.orWhere({
type: SubscriptionType.Rss,
})
if (type) {
queryBuilder.andWhere({

View file

@ -88,11 +88,6 @@ describe('Subscriptions API', () => {
it('should return subscriptions', async () => {
const res = await graphqlRequest(query, authToken).expect(200)
console.log(
'test subscriptions: ',
res.body.data.subscriptions.subscriptions
)
expect(res.body.data.subscriptions.subscriptions).to.eql(
subscriptions.map((sub) => ({
id: sub.id,
@ -101,6 +96,35 @@ describe('Subscriptions API', () => {
)
})
it('should return only newsletters when type newsletter supplied', async () => {
query = `
query {
subscriptions(type: NEWSLETTER) {
... on SubscriptionsSuccess {
subscriptions {
id
name
}
}
... on SubscriptionsError {
errorCodes
}
}
}
`
const newsletters = subscriptions.filter(
(s) => s.type == SubscriptionType.Newsletter
)
const res = await graphqlRequest(query, authToken).expect(200)
expect(res.body.data.subscriptions.subscriptions).to.eql(
newsletters.map((sub) => ({
id: sub.id,
name: sub.name,
}))
)
})
it('responds status code 400 when invalid query', async () => {
const invalidQuery = `
query {