Skip to content

Commit

Permalink
chore(application-system): Clean up old children residence change app…
Browse files Browse the repository at this point in the history
…lication (#16735)

* Remove pdf related endpoints from application controller

* Delete application controller dtos

* Remove file service related e2e tests

* Remove pdf references from application resolver and service with dtos

* Remove family matters hooks

* Removed old resident change from family-matters template dir

* Old CRC cleanup

* Re-add dokobit

* fix file service tests

* Fix pr

* PR comment

* fix tests

* Re-add missing stuff

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
norda-gunni and kodiakhq[bot] authored Nov 12, 2024
1 parent e4b2374 commit 0d7e478
Show file tree
Hide file tree
Showing 117 changed files with 20 additions and 6,144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
FormValue,
ExternalData,
TemplateApi,
PdfTypes,
ApplicationStatus,
ApplicationTemplate,
ApplicationContext,
Expand Down Expand Up @@ -69,17 +68,12 @@ import { CreateApplicationDto } from './dto/createApplication.dto'
import { UpdateApplicationDto } from './dto/updateApplication.dto'
import { AddAttachmentDto } from './dto/addAttachment.dto'
import { DeleteAttachmentDto } from './dto/deleteAttachment.dto'
import { GeneratePdfDto } from './dto/generatePdf.dto'
import { PopulateExternalDataDto } from './dto/populateExternalData.dto'
import { RequestFileSignatureDto } from './dto/requestFileSignature.dto'
import { UploadSignedFileDto } from './dto/uploadSignedFile.dto'
import { ApplicationValidationService } from './tools/applicationTemplateValidation.service'
import { ApplicationSerializer } from './tools/application.serializer'
import { UpdateApplicationStateDto } from './dto/updateApplicationState.dto'
import { ApplicationResponseDto } from './dto/application.response.dto'
import { PresignedUrlResponseDto } from './dto/presignedUrl.response.dto'
import { RequestFileSignatureResponseDto } from './dto/requestFileSignature.response.dto'
import { UploadSignedFileResponseDto } from './dto/uploadSignedFile.response.dto'
import { AssignApplicationDto } from './dto/assignApplication.dto'
import { verifyToken } from './utils/tokenUtils'
import { getApplicationLifecycle } from './utils/application'
Expand Down Expand Up @@ -891,140 +885,6 @@ export class ApplicationController {
return updatedApplication
}

@Scopes(ApplicationScope.write)
@Put('applications/:id/generatePdf')
@ApiParam({
name: 'id',
type: String,
required: true,
description: 'The id of the application to create a pdf for',
allowEmptyValue: false,
})
@ApiOkResponse({ type: PresignedUrlResponseDto })
async generatePdf(
@Param('id', new ParseUUIDPipe()) id: string,
@Body() input: GeneratePdfDto,
@CurrentUser() user: User,
): Promise<PresignedUrlResponseDto> {
const existingApplication =
await this.applicationAccessService.findOneByIdAndNationalId(id, user)
const url = await this.fileService.generatePdf(
existingApplication,
input.type,
)

this.auditService.audit({
auth: user,
action: 'generatePdf',
resources: existingApplication.id,
meta: { type: input.type },
})

return { url }
}

@Scopes(ApplicationScope.write)
@Put('applications/:id/requestFileSignature')
@ApiParam({
name: 'id',
type: String,
required: true,
description:
'The id of the application which the file signature is requested for.',
allowEmptyValue: false,
})
@ApiOkResponse({ type: RequestFileSignatureResponseDto })
async requestFileSignature(
@Param('id', new ParseUUIDPipe()) id: string,
@Body() input: RequestFileSignatureDto,
@CurrentUser() user: User,
): Promise<RequestFileSignatureResponseDto> {
const existingApplication =
await this.applicationAccessService.findOneByIdAndNationalId(id, user)
const { controlCode, documentToken } =
await this.fileService.requestFileSignature(
existingApplication,
input.type,
)

this.auditService.audit({
auth: user,
action: 'requestFileSignature',
resources: existingApplication.id,
meta: { type: input.type },
})

return { controlCode, documentToken }
}

@Scopes(ApplicationScope.write)
@Put('applications/:id/uploadSignedFile')
@ApiParam({
name: 'id',
type: String,
required: true,
description: 'The id of the application which the file was created for.',
allowEmptyValue: false,
})
@ApiOkResponse({ type: UploadSignedFileResponseDto })
async uploadSignedFile(
@Param('id', new ParseUUIDPipe()) id: string,
@Body() input: UploadSignedFileDto,
@CurrentUser() user: User,
): Promise<UploadSignedFileResponseDto> {
const existingApplication =
await this.applicationAccessService.findOneByIdAndNationalId(id, user)

await this.fileService.uploadSignedFile(
existingApplication,
input.documentToken,
input.type,
)

this.auditService.audit({
auth: user,
action: 'uploadSignedFile',
resources: existingApplication.id,
meta: { type: input.type },
})

return {
documentSigned: true,
}
}

@Scopes(ApplicationScope.read)
@Get('applications/:id/:pdfType/presignedUrl')
@ApiParam({
name: 'id',
type: String,
required: true,
description: 'The id of the application which the file was created for.',
allowEmptyValue: false,
})
@ApiOkResponse({ type: PresignedUrlResponseDto })
async getPresignedUrl(
@Param('id', new ParseUUIDPipe()) id: string,
@Param('pdfType') type: PdfTypes,
@CurrentUser() user: User,
): Promise<PresignedUrlResponseDto> {
const existingApplication =
await this.applicationAccessService.findOneByIdAndNationalId(id, user)
const url = await this.fileService.getPresignedUrl(
existingApplication,
type,
)

this.auditService.audit({
auth: user,
action: 'getPresignedUrl',
resources: existingApplication.id,
meta: { type },
})

return { url }
}

@Get('applications/:id/attachments/:attachmentKey/presigned-url')
@Scopes(ApplicationScope.read)
@Documentation({
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { ContentfulRepository } from '@island.is/cms'
import { setup } from '../../../../../test/setup'
import { environment } from '../../../../environments'
import { FileService } from '@island.is/application/api/files'
import { AppModule } from '../../../app.module'
import { FeatureFlagService } from '@island.is/nest/feature-flags'
import { MockFeatureFlagService } from './mockFeatureFlagService'
Expand Down Expand Up @@ -822,120 +821,6 @@ describe('Application system API', () => {
)
})

it('PUT /applications/:id/generatePdf should return a presigned url', async () => {
const expectPresignedUrl = 'presignedurl'
const type = 'ChildrenResidenceChange'

const fileService: FileService = app.get<FileService>(FileService)
jest
.spyOn(fileService, 'generatePdf')
.mockImplementation(() => Promise.resolve(expectPresignedUrl))

const creationResponse = await server
.post('/applications')
.send({
typeId: ApplicationTypes.CHILDREN_RESIDENCE_CHANGE,
})
.expect(201)

const res = await server
.put(`/applications/${creationResponse.body.id}/generatePdf`)
.send({
type: type,
})
.expect(200)

// Assert
expect(res.body).toEqual({ url: 'presignedurl' })
})

it('PUT /applications/:id/requestFileSignature should return a documentToken and controlCode', async () => {
const expectedControlCode = '0000'
const expectedDocumentToken = 'token'
const type = 'ChildrenResidenceChange'

const fileService: FileService = app.get<FileService>(FileService)
jest.spyOn(fileService, 'requestFileSignature').mockImplementation(() =>
Promise.resolve({
controlCode: expectedControlCode,
documentToken: expectedDocumentToken,
}),
)

const creationResponse = await server
.post('/applications')
.send({
typeId: ApplicationTypes.CHILDREN_RESIDENCE_CHANGE,
})
.expect(201)

const res = await server
.put(`/applications/${creationResponse.body.id}/requestFileSignature`)
.send({
type: type,
})
.expect(200)

// Assert
expect(res.body).toEqual({
controlCode: expectedControlCode,
documentToken: expectedDocumentToken,
})
})

it('GET /applications/:id/presignedUrl should return a presigned url', async () => {
const expectedPresignedUrl = 'presignedurl'
const type = 'ChildrenResidenceChange'

const fileService: FileService = app.get<FileService>(FileService)
jest
.spyOn(fileService, 'getPresignedUrl')
.mockImplementation(() => Promise.resolve(expectedPresignedUrl))

const creationResponse = await server
.post('/applications')
.send({
typeId: ApplicationTypes.CHILDREN_RESIDENCE_CHANGE,
})
.expect(201)

const res = await server
.get(`/applications/${creationResponse.body.id}/${type}/presignedUrl`)
.send({
type: type,
})
.expect(200)

// Assert
expect(res.body).toEqual({ url: expectedPresignedUrl })
})

it('PUT /applications/:id/uploadSignedFile should return that document has been signed', async () => {
const type = 'ChildrenResidenceChange'
const fileService: FileService = app.get<FileService>(FileService)
jest
.spyOn(fileService, 'uploadSignedFile')
.mockImplementation(() => Promise.resolve())

const creationResponse = await server
.post('/applications')
.send({
typeId: ApplicationTypes.CHILDREN_RESIDENCE_CHANGE,
})
.expect(201)

const res = await server
.put(`/applications/${creationResponse.body.id}/uploadSignedFile`)
.send({
type: type,
documentToken: '0000',
})
.expect(200)

// Assert
expect(res.body).toEqual({ documentSigned: true })
})

it('should update external data with template api module action response', async () => {
const creationResponse = await server
.post('/applications')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,6 @@ describe('Application system API delegation guard', () => {
key: '',
},
},
{
method: 'PUT',
endpoint: `/applications/${uuid.uuid()}/generatePdf`,
send: {
type: '',
},
},
{
method: 'PUT',
endpoint: `/applications/${uuid.uuid()}/requestFileSignature`,
send: {
type: '',
},
},
{
method: 'GET',
endpoint: `/applications/${uuid.uuid()}/test/presignedUrl`,
send: {},
},
{
method: 'PUT',
endpoint: `/applications/${uuid.uuid()}/uploadSignedFile`,
send: {
type: '',
documentToken: '0000',
},
},
{
method: 'PUT',
endpoint: `/applications/assign`,
Expand Down
Loading

0 comments on commit 0d7e478

Please sign in to comment.