Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(personal-representative): PR Delegation Type #14757

Merged
merged 29 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c855e2c
created personal representative delegation type and conencted it to g…
GunnlaugurG May 3, 2024
a1e8633
WIP
GunnlaugurG May 8, 2024
895577b
destroy PRDT on PR delete
GunnlaugurG May 8, 2024
530293f
fix tests and CRUD ready
GunnlaugurG May 13, 2024
12c71a2
fix build error for creationOptional
GunnlaugurG May 13, 2024
152c9d0
Fix delegation tests
GunnlaugurG May 14, 2024
b504b94
Fix promise in PersRep tests
GunnlaugurG May 14, 2024
32351ef
Fixing long pg query identifier in personal representative.
saevarma May 14, 2024
fbe8070
fix broken tests
GunnlaugurG May 15, 2024
d895f3c
fix actor delegation tests
GunnlaugurG May 15, 2024
abc2a0b
clear test db in afterAll
GunnlaugurG May 15, 2024
c0402e6
fix pr-public-api tests
GunnlaugurG May 16, 2024
c109cf9
chore: nx format:write update dirty files
andes-it May 16, 2024
83f9c35
Merge branch 'main' into feat/PR-Delegation-Type
GunnlaugurG May 16, 2024
aec2b1f
improved testing for personal represetative
GunnlaugurG May 16, 2024
3a326f3
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
816f61c
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
7411d0e
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
d89c631
cleanup
GunnlaugurG May 16, 2024
5f6a440
pr comment changes
GunnlaugurG May 21, 2024
aff3d94
pr comment changes
GunnlaugurG May 21, 2024
e6eba48
pr comment changes
GunnlaugurG May 21, 2024
c6899ef
fix codegen
GunnlaugurG May 21, 2024
f592eb9
fix failing test
GunnlaugurG May 21, 2024
24d5b06
fix service auth public api tests
GunnlaugurG May 21, 2024
cf3ae76
fix service auth public api tests
GunnlaugurG May 21, 2024
340338a
Pr comment changes
GunnlaugurG May 23, 2024
c9ab79f
Pr comment changes
GunnlaugurG May 23, 2024
4b35634
Merge branch 'main' into feat/PR-Delegation-Type
kodiakhq[bot] May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
ClientAllowedScope,
Delegation,
DelegationDTO,
DelegationProviderModel,
DelegationType,
DelegationTypeModel,
Domain,
InactiveReason,
MergedDelegationDTO,
PersonalRepresentative,
PersonalRepresentativeDelegationTypeModel,
PersonalRepresentativeRight,
PersonalRepresentativeRightType,
PersonalRepresentativeScopePermission,
Expand Down Expand Up @@ -52,6 +55,8 @@ import {
getScopePermission,
personalRepresentativeType,
} from '../../../test/stubs/personalRepresentativeStubs'
import { AuthDelegationProvider } from 'delegation'
import { getPersonalRepresentativeDelegationType } from '@island.is/shared/types'

describe('DelegationsController', () => {
describe('Given a user is authenticated', () => {
Expand All @@ -63,7 +68,10 @@ describe('DelegationsController', () => {
let prRightsModel: typeof PersonalRepresentativeRight
let prRightTypeModel: typeof PersonalRepresentativeRightType
let prTypeModel: typeof PersonalRepresentativeType
let prDelegationTypeModel: typeof PersonalRepresentativeDelegationTypeModel
let delegationTypeModel: typeof DelegationTypeModel
let nationalRegistryApi: NationalRegistryClientService
let delegationProviderModel: typeof DelegationProviderModel

const userNationalId = getFakeNationalId()

Expand Down Expand Up @@ -102,13 +110,42 @@ describe('DelegationsController', () => {
prScopePermission = app.get<typeof PersonalRepresentativeScopePermission>(
getModelToken(PersonalRepresentativeScopePermission),
)
prDelegationTypeModel = app.get<
typeof PersonalRepresentativeDelegationTypeModel
>(getModelToken(PersonalRepresentativeDelegationTypeModel))
delegationTypeModel = app.get<typeof DelegationTypeModel>(
getModelToken(DelegationTypeModel),
)
delegationProviderModel = app.get<typeof DelegationProviderModel>(
getModelToken(DelegationProviderModel),
)
nationalRegistryApi = app.get(NationalRegistryClientService)
})

afterAll(async () => {
await app.cleanUp()
})

const createDelegationTypeAndProvider = async (rightCode: string[]) => {
const newDelegationProvider = await delegationProviderModel.create({
id: AuthDelegationProvider.PersonalRepresentativeRegistry,
name: 'Talsmannagrunnur',
description: 'Talsmannagrunnur',
delegationTypes: [],
})

await delegationTypeModel.bulkCreate(
rightCode.map((code) => {
return {
id: getPersonalRepresentativeDelegationType(code),
providerId: newDelegationProvider.id,
name: getPersonalRepresentativeDelegationType(code),
description: `Personal representative delegation type for right type ${code}`,
}
}),
)
}

describe('and given we have 3 valid, 1 not yet active and 1 outdate right types', () => {
type rightsTypeStatus = 'valid' | 'unactivated' | 'outdated'
type rightsType = [code: string, status: rightsTypeStatus]
Expand Down Expand Up @@ -139,6 +176,7 @@ describe('DelegationsController', () => {
}
}),
)
await createDelegationTypeAndProvider(rightsTypes.map(([code]) => code))
})

afterAll(async () => {
Expand All @@ -148,6 +186,18 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await delegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
await delegationProviderModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
})

describe.each([
Expand Down Expand Up @@ -193,6 +243,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

for (let i = 0; i < outdated; i++) {
Expand All @@ -209,6 +264,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('outdated', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('outdated'),
})
}

for (let i = 0; i < unactivated; i++) {
Expand All @@ -225,6 +285,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('unactivated', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('unactivated'),
})
}

for (let i = 0; i < deceased; i++) {
Expand All @@ -241,6 +306,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

for (let i = 0; i < nationalRegistryErrors; i++) {
Expand All @@ -260,6 +330,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

const nationalRegistryUsers = [
Expand Down Expand Up @@ -314,6 +389,12 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await prDelegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
})

describe('when user calls GET /v2/delegations', () => {
Expand Down Expand Up @@ -484,6 +565,12 @@ describe('DelegationsController', () => {
getPersonalRepresentativeRights(r, relationship.id),
),
)
await prDelegationTypeModel.bulkCreate(
rights.map((r) => ({
personalRepresentativeId: relationship.id,
delegationTypeId: getPersonalRepresentativeDelegationType(r),
})),
)
})

afterAll(async () => {
Expand All @@ -499,6 +586,12 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await prDelegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
})

describe('when user calls GET /delegations/scopes', () => {
Expand Down Expand Up @@ -559,6 +652,8 @@ describe('DelegationsController', () => {
}
}),
)

await createDelegationTypeAndProvider(rightsTypes.map(([code]) => code))
})

afterAll(async () => {
Expand All @@ -568,6 +663,18 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await delegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
await delegationProviderModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
})

describe.each([
Expand Down Expand Up @@ -613,6 +720,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

for (let i = 0; i < outdated; i++) {
Expand All @@ -629,6 +741,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('outdated', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('outdated'),
})
}

for (let i = 0; i < unactivated; i++) {
Expand All @@ -645,6 +762,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('unactivated', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('unactivated'),
})
}

for (let i = 0; i < deceased; i++) {
Expand All @@ -661,6 +783,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

for (let i = 0; i < nationalRegistryErrors; i++) {
Expand All @@ -680,6 +807,11 @@ describe('DelegationsController', () => {
await prRightsModel.create(
getPersonalRepresentativeRights('valid1', relationship.id),
)
await prDelegationTypeModel.create({
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType('valid1'),
})
}

const nationalRegistryUsers = [
Expand Down Expand Up @@ -728,6 +860,12 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await prDelegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
await prModel.destroy({
where: {},
cascade: true,
Expand Down Expand Up @@ -907,6 +1045,15 @@ describe('DelegationsController', () => {
getPersonalRepresentativeRights(r, relationship.id),
),
)
await prDelegationTypeModel.bulkCreate(
rights.map((r) => {
return {
personalRepresentativeId: relationship.id,
delegationTypeId:
getPersonalRepresentativeDelegationType(r),
}
}),
)
})

afterAll(async () => {
Expand All @@ -922,6 +1069,12 @@ describe('DelegationsController', () => {
truncate: true,
force: true,
})
await prDelegationTypeModel.destroy({
where: {},
cascade: true,
truncate: true,
force: true,
})
})

describe('when user calls GET /delegations/scopes', () => {
Expand Down
Loading
Loading