Skip to content

Commit

Permalink
Merge branch 'configurable-roles' into configurable-roles-qa
Browse files Browse the repository at this point in the history
  • Loading branch information
Zangetsu101 committed Jan 22, 2025
2 parents fe5948c + 26d09b2 commit 0f1682b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
24 changes: 1 addition & 23 deletions packages/client/src/workqueue/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
UPDATE_WORKQUEUE_PAGINATION,
IQueryData
} from './actions'
import { Scope, SCOPES } from '@opencrvs/commons/client'
import { SCOPES } from '@opencrvs/commons/client'

export const EVENT_STATUS = {
IN_PROGRESS: 'IN_PROGRESS',
Expand Down Expand Up @@ -129,7 +129,6 @@ async function getFilteredDeclarations(
unassignedDeclarations: IDeclaration[]
}> {
const state = getState()
const scope = getScope(state)
const savedDeclarations = state.declarationsState.declarations

const workqueueDeclarations = Object.entries(workqueue.data).flatMap(
Expand All @@ -138,27 +137,6 @@ async function getFilteredDeclarations(
}
) as Array<GQLEventSearchSet | null>

// for field agent, no declarations should be unassigned
// for registration agent, sent for approval declarations should not be unassigned

// for other agents, check if the status of workqueue declaration
// has changed and if that declaration is saved in the store
// also declaration should not show as unassigned when it is being submitted
const declareScopes = [
SCOPES.RECORD_DECLARE_BIRTH,
SCOPES.RECORD_DECLARE_DEATH,
SCOPES.RECORD_DECLARE_MARRIAGE,
SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION,
SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION,
SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION
] as Scope[]

if (scope?.some((x) => declareScopes.includes(x)))
return {
currentlyDownloadedDeclarations: savedDeclarations,
unassignedDeclarations: []
}

const unassignedDeclarations = workqueueDeclarations
.filter(
(dec) =>
Expand Down
40 changes: 15 additions & 25 deletions packages/events/src/router/locations/locations.set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,25 @@ test('prevents unauthorized access from registrar', async () => {

test('Allows national system admin to set locations', async () => {
const { user, generator } = await setupTestCase()
const nationalSystemAdminClient = createTestClient(user, [
SCOPES.CONFIG_UPDATE_ALL
])
const dataSeedingClient = createTestClient(user, [SCOPES.USER_DATA_SEEDING])

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 () => {
const { user } = await setupTestCase()
const nationalSystemAdminClient = createTestClient(user, [
SCOPES.CONFIG_UPDATE_ALL
])
const dataSeedingClient = createTestClient(user, [SCOPES.USER_DATA_SEEDING])

await expect(
nationalSystemAdminClient.locations.set([])
dataSeedingClient.locations.set([])
).rejects.toThrowErrorMatchingSnapshot()
})

test('Creates single location', async () => {
const { user } = await setupTestCase()
const nationalSystemAdminClient = createTestClient(user, [
SCOPES.CONFIG_UPDATE_ALL
])
const dataSeedingClient = createTestClient(user, [SCOPES.USER_DATA_SEEDING])

const locationPayload = [
{
Expand All @@ -57,19 +51,17 @@ test('Creates single location', 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).toHaveLength(1)
expect(locations).toMatchObject(locationPayload)
})

test('Creates multiple locations', async () => {
const { user, generator } = await setupTestCase()
const nationalSystemAdminClient = createTestClient(user, [
SCOPES.CONFIG_UPDATE_ALL
])
const dataSeedingClient = createTestClient(user, [SCOPES.USER_DATA_SEEDING])

const parentId = 'parent-id'

Expand All @@ -80,32 +72,30 @@ 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 { user, generator } = await setupTestCase()
const nationalSystemAdminClient = createTestClient(user, [
SCOPES.CONFIG_UPDATE_ALL
])
const dataSeedingClient = createTestClient(user, [SCOPES.USER_DATA_SEEDING])

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 0f1682b

Please sign in to comment.