Skip to content

Commit

Permalink
fixed broken tests 😵
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarsson committed Jun 4, 2024
1 parent 6f3a580 commit c3f98b6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/adverts/adverts.gql.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const advertsGqlSchema = /* GraphQL */ `
isReservedBySome: Boolean!
isCollectedBySome: Boolean!
isPicked: Boolean!
waitlistCount: Number!
waitlistCount: Int!
returnInfo: [AdvertReturnInfo]!
claims: [AdvertClaim]!
}
Expand Down
91 changes: 51 additions & 40 deletions src/profile/e2e-test/remove-profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,59 @@ const range = (n: number): any[] => Object.keys([...new Array(n)])

describe('removeProfile', () => {
it('delete profile data and associated adverts', () =>
end2endTest(null, async ({ user, profiles, adverts, gqlRequest }) => {
const addProfile = (id: string) => {
// eslint-disable-next-line no-param-reassign
profiles[id] = createEmptyProfile()
}
const addAdvert = (advert: Advert) => {
// eslint-disable-next-line no-param-reassign
adverts[advert.id] = advert
}
end2endTest(
null,
async ({ user, profiles, adverts, loginPolicies, gqlRequest }) => {
await loginPolicies.updateLoginPolicies([
{
emailPattern: user.id,
roles: ['canManageProfile'],
},
])
const addProfile = (id: string) => {
// eslint-disable-next-line no-param-reassign
profiles[id] = createEmptyProfile()
}
const addAdvert = (advert: Advert) => {
// eslint-disable-next-line no-param-reassign
adverts[advert.id] = advert
}

// setup some profiles
addProfile('keep.me')
addProfile('keep.me.too')
addProfile(user.id)
// setup some profiles
addProfile('keep.me')
addProfile('keep.me.too')
addProfile(user.id)

// setup some adverts
addAdvert(createEmptyAdvert({ id: 'keep.1', createdBy: 'keep.me' }))
addAdvert(createEmptyAdvert({ id: 'keep.2', createdBy: 'keep.me.too' }))
range(1000).forEach(i =>
addAdvert(createEmptyAdvert({ id: `remove.${i}`, createdBy: user.id }))
)
addAdvert(
createEmptyAdvert({ id: 'keep.last', createdBy: 'keep.me.too' })
)
// setup some adverts
addAdvert(createEmptyAdvert({ id: 'keep.1', createdBy: 'keep.me' }))
addAdvert(createEmptyAdvert({ id: 'keep.2', createdBy: 'keep.me.too' }))
range(1000).forEach(i =>
addAdvert(
createEmptyAdvert({ id: `remove.${i}`, createdBy: user.id })
)
)
addAdvert(
createEmptyAdvert({ id: 'keep.last', createdBy: 'keep.me.too' })
)

const { status, body } = await gqlRequest(
/* GraphQL */ `
mutation Mutation($input: RemoveProfileInput!) {
removeProfile(input: $input) {
success
const { status, body } = await gqlRequest(
/* GraphQL */ `
mutation Mutation($input: RemoveProfileInput!) {
removeProfile(input: $input) {
success
}
}
}
`,
{ input: { removeAdverts: true } }
)
expect(status).toBe(StatusCodes.OK)
expect(body?.data?.removeProfile?.success).toBe(true)
expect(Object.keys(profiles)).toMatchObject(['keep.me', 'keep.me.too'])
expect(Object.keys(adverts)).toMatchObject([
'keep.1',
'keep.2',
'keep.last',
])
}))
`,
{ input: { removeAdverts: true } }
)
expect(status).toBe(StatusCodes.OK)
expect(body?.data?.removeProfile?.success).toBe(true)
expect(Object.keys(profiles)).toMatchObject(['keep.me', 'keep.me.too'])
expect(Object.keys(adverts)).toMatchObject([
'keep.1',
'keep.2',
'keep.last',
])
}
))
})
9 changes: 8 additions & 1 deletion src/profile/e2e-test/update-profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import type { ProfileInput } from '../types'

describe('getProfile', () => {
it('returns repository content with email set to calling user', () =>
end2endTest(null, async ({ user, profiles, gqlRequest }) => {
end2endTest(null, async ({ user, profiles, loginPolicies, gqlRequest }) => {
await loginPolicies.updateLoginPolicies([
{
emailPattern: user.id,
roles: ['canManageProfile'],
},
])

const input: ProfileInput = {
name: 'Foo',
phone: '123-45678',
Expand Down

0 comments on commit c3f98b6

Please sign in to comment.