Skip to content

Commit

Permalink
fix: update scope of event tests of seeding users (#8324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 authored Jan 13, 2025
1 parent c946959 commit 5c44f51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/events/src/router/locations.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { createTestClient } from '@events/tests/utils'
import { payloadGenerator } from '@events/tests/generators'
import { SCOPES } from '@opencrvs/commons'

const nationalSystemAdminClient = createTestClient([SCOPES.CONFIG_UPDATE_ALL])
const dataSeedingClient = createTestClient([SCOPES.USER_DATA_SEEDING])
const generator = payloadGenerator()

test('Returns empty list when no locations are set', async () => {
const locations = await nationalSystemAdminClient.locations.get()
const locations = await dataSeedingClient.locations.get()

expect(locations).toEqual([])
})
Expand All @@ -26,18 +26,18 @@ test('Returns single location in right format', async () => {
{ id: '123-456-789', partOf: null, name: 'Location foobar' }
]

await nationalSystemAdminClient.locations.set(setLocationPayload)
await dataSeedingClient.locations.set(setLocationPayload)

const locations = await nationalSystemAdminClient.locations.get()
const locations = await dataSeedingClient.locations.get()

expect(locations).toHaveLength(1)
expect(locations).toMatchObject(setLocationPayload)
})

test('Returns multiple locations', async () => {
await nationalSystemAdminClient.locations.set(generator.locations.set(5))
await dataSeedingClient.locations.set(generator.locations.set(5))

const locations = await nationalSystemAdminClient.locations.get()
const locations = await dataSeedingClient.locations.get()

expect(locations).toHaveLength(5)
})
24 changes: 12 additions & 12 deletions packages/events/src/router/locations.set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createTestClient } from '@events/tests/utils'
import { payloadGenerator } from '@events/tests/generators'
import { SCOPES } from '@opencrvs/commons'

const nationalSystemAdminClient = createTestClient([SCOPES.CONFIG_UPDATE_ALL])
const dataSeedingClient = createTestClient([SCOPES.USER_DATA_SEEDING])

const registrarClient = createTestClient()

Expand All @@ -24,15 +24,15 @@ test('prevents unauthorized access from registrar', async () => {
).rejects.toThrowErrorMatchingSnapshot()
})

test('Allows national system admin to set locations', async () => {
test('Allows client to set locations', async () => {
await expect(
nationalSystemAdminClient.locations.set(generator.locations.set(1))
dataSeedingClient.locations.set(generator.locations.set(1))
).resolves.toEqual(undefined)
})

test('Prevents sending empty payload', async () => {
await expect(
nationalSystemAdminClient.locations.set([])
dataSeedingClient.locations.set([])
).rejects.toThrowErrorMatchingSnapshot()
})

Expand All @@ -41,9 +41,9 @@ test('Creates single location', async () => {
{ id: '123-456-789', partOf: null, name: 'Location foobar' }
]

await nationalSystemAdminClient.locations.set(locationPayload)
await dataSeedingClient.locations.set(locationPayload)

const locations = await nationalSystemAdminClient.locations.get()
const locations = await dataSeedingClient.locations.get()

expect(locations).toHaveLength(1)
expect(locations).toMatchObject(locationPayload)
Expand All @@ -59,27 +59,27 @@ test('Creates multiple locations', async () => {
{}
])

await nationalSystemAdminClient.locations.set(locationPayload)
await dataSeedingClient.locations.set(locationPayload)

const locations = await nationalSystemAdminClient.locations.get()
const locations = await dataSeedingClient.locations.get()

expect(locations).toEqual(locationPayload)
})

test('Removes existing locations not in payload', async () => {
const initialPayload = generator.locations.set(5)

await nationalSystemAdminClient.locations.set(initialPayload)
await dataSeedingClient.locations.set(initialPayload)

const initialLocations = await nationalSystemAdminClient.locations.get()
const initialLocations = await dataSeedingClient.locations.get()
expect(initialLocations).toHaveLength(initialPayload.length)

const [removedLocation, ...remainingLocationsPayload] = initialPayload

await nationalSystemAdminClient.locations.set(remainingLocationsPayload)
await dataSeedingClient.locations.set(remainingLocationsPayload)

const remainingLocationsAfterDeletion =
await nationalSystemAdminClient.locations.get()
await dataSeedingClient.locations.get()

expect(remainingLocationsAfterDeletion).toHaveLength(
remainingLocationsPayload.length
Expand Down

0 comments on commit 5c44f51

Please sign in to comment.