Skip to content

Commit

Permalink
Fix admin api scope added delegation type update to only update reque…
Browse files Browse the repository at this point in the history
…sted type.
  • Loading branch information
saevarma committed Sep 11, 2024
1 parent 8eb83b6 commit 6200a9a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SequelizeConfigService,
TranslatedValueDto,
ApiScopeDelegationType,
AdminPatchScopeDto,
AdminPatchScopeDto, ApiScope,
} from '@island.is/auth-api-lib'
import { FixtureFactory } from '@island.is/services/auth/testing'
import {
Expand Down Expand Up @@ -763,6 +763,7 @@ describe('MeScopesController', () => {
let app: TestApp
let server: request.SuperTest<request.Test>
let apiScopeDelegationTypeModel: typeof ApiScopeDelegationType
let fixtureFactory: FixtureFactory

beforeAll(async () => {
app = await setupApp({
Expand All @@ -772,6 +773,7 @@ describe('MeScopesController', () => {
dbType: 'postgres',
})
server = request(app.getHttpServer())
fixtureFactory = new FixtureFactory(app)

apiScopeDelegationTypeModel = await app.get(
getModelToken(ApiScopeDelegationType),
Expand Down Expand Up @@ -886,6 +888,59 @@ describe('MeScopesController', () => {
},
})
})

it('should only update requested delegation setting fields', async () => {
// Arrange
// Create new subject under testing test data to control initial state of delegation settings.
const sutScope = await fixtureFactory.createApiScope({
domainName: TENANT_ID,
allowExplicitDelegationGrant: true,
supportedDelegationTypes: [
AuthDelegationType.Custom,
],
})

// Act - Update partially delegation setting
const response = await server
.patch(
`/v2/me/tenants/${TENANT_ID}/scopes/${encodeURIComponent(
sutScope.name,
)}`,
)
.send({
addedDelegationTypes: [
AuthDelegationType.ProcurationHolder,
],
})

// Assert that we only updated requested delegation setting fields
expect(response.status).toEqual(200)
expect(response.body).toMatchObject({
...sutScope.toDTO(),
displayName: [{
locale: 'is',
value: sutScope.displayName,
}],
description: [{
locale: 'is',
value: sutScope.description,
}],
grantToProcuringHolders: true,
supportedDelegationTypes: expect.arrayContaining([
AuthDelegationType.Custom,
AuthDelegationType.ProcurationHolder,
]),
} as AdminScopeDTO)
const apiScopeDelegationTypes = await apiScopeDelegationTypeModel.findAll(
{
where: {
apiScopeName: sutScope.name,
},
},
)

expect(apiScopeDelegationTypes).toHaveLength(2)
})
})

describe('POST: /v2/me/tenants/:tenantId/scopes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ export class AdminScopeService {
) {
await this.apiScope.update(
{
grantToLegalGuardians,
grantToPersonalRepresentatives,
grantToProcuringHolders,
allowExplicitDelegationGrant,
...(grantToLegalGuardians ? {grantToLegalGuardians} : {}),
...(grantToPersonalRepresentatives ? {grantToPersonalRepresentatives} : {}),
...(grantToProcuringHolders ? {grantToProcuringHolders} : {}),
...(allowExplicitDelegationGrant ? {allowExplicitDelegationGrant} : {}),
},
{
transaction,
Expand Down

0 comments on commit 6200a9a

Please sign in to comment.