mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add tests
This commit is contained in:
parent
75974c772e
commit
1837f31906
2 changed files with 38 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
createTestNewsletterEmail,
|
||||
createTestSubscription,
|
||||
createTestUser,
|
||||
deleteTestUser,
|
||||
getNewsletterEmail,
|
||||
|
|
@ -35,6 +36,9 @@ describe('Newsletters API', () => {
|
|||
'Test_email_address_2@omnivore.app'
|
||||
)
|
||||
newsletterEmails = [newsletterEmail1, newsletterEmail2]
|
||||
|
||||
// create testing subscriptions
|
||||
await createTestSubscription(user, 'sub', newsletterEmail2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
|
|
@ -51,6 +55,8 @@ describe('Newsletters API', () => {
|
|||
id
|
||||
address
|
||||
confirmationCode
|
||||
createdAt
|
||||
subscriptionCount
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,17 +69,31 @@ describe('Newsletters API', () => {
|
|||
|
||||
it('responds with newsletter emails sort by created_at desc', async () => {
|
||||
const response = await graphqlRequest(query, authToken).expect(200)
|
||||
expect(response.body.data.newsletterEmails.newsletterEmails).to.eqls(
|
||||
newsletterEmails
|
||||
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
|
||||
.map((value) => {
|
||||
return {
|
||||
id: value.id,
|
||||
address: value.address,
|
||||
confirmationCode: value.confirmationCode,
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(
|
||||
response.body.data.newsletterEmails.newsletterEmails.map((e: any) => {
|
||||
return {
|
||||
...e,
|
||||
createdAt: new Date(e.createdAt).toISOString().split('.')[0] + 'Z',
|
||||
}
|
||||
})
|
||||
).to.eqls([
|
||||
{
|
||||
id: newsletterEmails[1].id,
|
||||
address: newsletterEmails[1].address,
|
||||
confirmationCode: newsletterEmails[1].confirmationCode,
|
||||
createdAt:
|
||||
newsletterEmails[1].createdAt.toISOString().split('.')[0] + 'Z',
|
||||
subscriptionCount: 1,
|
||||
},
|
||||
{
|
||||
id: newsletterEmails[0].id,
|
||||
address: newsletterEmails[0].address,
|
||||
confirmationCode: newsletterEmails[0].confirmationCode,
|
||||
createdAt:
|
||||
newsletterEmails[0].createdAt.toISOString().split('.')[0] + 'Z',
|
||||
subscriptionCount: 0,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('responds status code 400 when invalid query', async () => {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import { SaveContext } from '../../src/services/save_email'
|
|||
import { createPubSubClient } from '../../src/datalayer/pubsub'
|
||||
import { getPageByParam } from '../../src/elastic/pages'
|
||||
import nock from 'nock'
|
||||
import { getRepository } from '../../src/entity/utils'
|
||||
import { Subscription } from '../../src/entity/subscription'
|
||||
|
||||
describe('saveNewsletterEmail', () => {
|
||||
const fakeContent = 'fake content'
|
||||
|
|
@ -55,6 +57,11 @@ describe('saveNewsletterEmail', () => {
|
|||
expect(page?.title).to.equal(title)
|
||||
expect(page?.author).to.equal(author)
|
||||
expect(page?.content).to.contain(fakeContent)
|
||||
|
||||
const subscriptions = await getRepository(Subscription).findBy({
|
||||
newsletterEmail: { id: email.id },
|
||||
})
|
||||
expect(subscriptions).not.to.be.empty
|
||||
})
|
||||
|
||||
it('should adds a Newsletter label to that page', async () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue