Skip to content

Commit

Permalink
Merge branch 'main' into j-s/max-length-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 18, 2024
2 parents 84d5826 + d33043f commit 1562e0c
Show file tree
Hide file tree
Showing 78 changed files with 641 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,20 @@ const Processing: FC = () => {
)

useEffect(() => {
if (!personData || !personData.items || personData.items.length === 0) {
setNationalIdNotFound(true)
if (!civilClaimantNationalIdUpdate) {
return
}

setNationalIdNotFound(false)
const items = personData?.items || []
const person = items[0]

setNationalIdNotFound(items.length === 0)

const update = {
caseId: workingCase.id,
civilClaimantId: civilClaimantNationalIdUpdate?.civilClaimantId || '',
name: personData?.items[0].name,
nationalId: personData.items[0].kennitala,
civilClaimantId: civilClaimantNationalIdUpdate.civilClaimantId || '',
nationalId: civilClaimantNationalIdUpdate.nationalId,
...(person?.name ? { name: person.name } : {}),
}

handleUpdateCivilClaimant(update)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,7 @@ export const getThemeConfig = (
}
}

return {
themeConfig: {
headerColorScheme: 'white',
headerButtonColorScheme: 'negative',
footerVersion,
},
}
return { themeConfig: { footerVersion } }
}

export const OrganizationHeader: React.FC<
Expand Down
3 changes: 2 additions & 1 deletion apps/web/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const PROJECT_STORIES_TAG_ID = '9yqOTwQYzgyej5kItFTtd'
export const ADGERDIR_INDIVIDUALS_TAG_ID = '4kLt3eRht5yJoakIHWsusb'
export const ADGERDIR_COMPANIES_TAG_ID = '4ZWcwoW2IiB2AhtzQpzdIW'
export const FRONTPAGE_NEWS_TAG_ID = 'forsidufrettir'
export const PLAUSIBLE_SCRIPT_SRC = 'https://plausible.io/js/plausible.js'
export const PLAUSIBLE_SCRIPT_SRC =
'https://plausible.io/js/script.outbound-links.js'
export const DIGITAL_ICELAND_PLAUSIBLE_TRACKING_DOMAIN =
'island.is/s/stafraent-island'
4 changes: 4 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export const buildDateField = (
const {
maxDate,
minDate,
minYear,
maxYear,
excludeDates,
placeholder,
backgroundColor = 'blue',
Expand All @@ -130,6 +132,8 @@ export const buildDateField = (
placeholder,
maxDate,
minDate,
minYear,
maxYear,
excludeDates,
type: FieldTypes.DATE,
component: FieldComponents.DATE,
Expand Down
5 changes: 5 additions & 0 deletions libs/application/core/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ export const coreErrorMessages = defineMessages({
defaultMessage: 'Þú uppfyllir ekki skilyrði fyrir umsókn um nafnskírteini',
description: 'Requirements for id card application not met',
},
drivingLicenseBookActiveBookNotFound: {
id: 'application.system:core.fetch.data.drivingLicenseBookActiveBookNotFound',
defaultMessage: 'Ekki fannst virk ökunámsbók',
description: 'Did not find active student book',
},
})

export const coreDelegationsMessages = defineMessages({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { Test } from '@nestjs/testing'
import { SharedTemplateApiService } from './shared.service'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { EmailService } from '@island.is/email-service'
import { SmsService } from '@island.is/nova-sms'
import { ApplicationService } from '@island.is/application/api/core'
import { PaymentService } from '@island.is/application/api/payment'
import { sharedModuleConfig } from './shared.config'
import { FormValue } from '@island.is/application/types'
import {
Application,
ApplicationStatus,
ActionCardMetaData,
} from '@island.is/application/types'
import { ApplicationTypes } from '@island.is/application/types'

describe('SharedTemplateApiService', () => {
let service: SharedTemplateApiService
let smsService: jest.Mocked<SmsService>
let logger: jest.Mocked<Logger>

const mockActionCard: ActionCardMetaData = {
title: 'Sample Application',
description: 'This is a sample application description',
tag: {
label: 'In Review',
variant: 'blue',
},
history: [
{
date: new Date('2024-03-20'),
log: 'Application submitted',
},
],
}

const mockApplication: Application<FormValue> = {
id: '12345-abcde',
state: 'submitted',
actionCard: mockActionCard,
applicant: 'user123',
assignees: ['reviewer1', 'reviewer2'],
applicantActors: ['user123'],
typeId: ApplicationTypes.EXAMPLE,
modified: new Date('2024-03-20T10:30:00'),
created: new Date('2024-03-19T15:45:00'),
answers: {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
},
externalData: {},
name: 'John Doe Application',
institution: 'Example University',
progress: 75,
status: ApplicationStatus.IN_PROGRESS,
draftTotalSteps: 4,
draftFinishedSteps: 3,
}

const mockConfig = {
templateApi: {
clientLocationOrigin: 'http://example.com',
jwtSecret: 'secret',
email: '[email protected]',
},
}

beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
SharedTemplateApiService,
{
provide: LOGGER_PROVIDER,
useValue: {
warn: jest.fn(),
},
},
{
provide: EmailService,
useValue: {},
},
{
provide: SmsService,
useValue: {
sendSms: jest.fn(),
},
},
{
provide: sharedModuleConfig.KEY,
useValue: mockConfig,
},
{
provide: ApplicationService,
useValue: {},
},
{
provide: PaymentService,
useValue: {},
},
],
}).compile()

service = module.get<SharedTemplateApiService>(SharedTemplateApiService)
smsService = module.get(SmsService)
logger = module.get(LOGGER_PROVIDER)
})

describe('sendSms', () => {
it('should successfully send an SMS with normalized phone number', async () => {
// Arrange
const mockSmsTemplateGenerator = jest.fn().mockReturnValue({
phoneNumber: '+354 1234567',
message: 'Test message',
})

// Act
await service.sendSms(mockSmsTemplateGenerator, mockApplication)

// Assert
expect(mockSmsTemplateGenerator).toHaveBeenCalledWith(mockApplication, {
clientLocationOrigin: mockConfig.templateApi.clientLocationOrigin,
})
expect(smsService.sendSms).toHaveBeenCalledWith('1234567', 'Test message')
expect(logger.warn).toHaveBeenCalledTimes(2)
})

it('should normalize phone numbers with special characters', async () => {
// Arrange
const mockSmsTemplateGenerator = jest.fn().mockReturnValue({
phoneNumber: '+354-123-4567',
message: 'Test message',
})

// Act
await service.sendSms(mockSmsTemplateGenerator, mockApplication)

// Assert
expect(smsService.sendSms).toHaveBeenCalledWith('1234567', 'Test message')
expect(logger.warn).toHaveBeenCalledTimes(2)
})

it('should handle phone numbers longer than 7 digits', async () => {
// Arrange
const mockSmsTemplateGenerator = jest.fn().mockReturnValue({
phoneNumber: '3541234567',
message: 'Test message',
})

// Act
await service.sendSms(mockSmsTemplateGenerator, mockApplication)

// Assert
expect(smsService.sendSms).toHaveBeenCalledWith('1234567', 'Test message')
expect(logger.warn).toHaveBeenCalledTimes(1)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export class SharedTemplateApiService {
clientLocationOrigin,
})

return this.smsService.sendSms(phoneNumber, message)
const normalizedPhoneNumber = this.normalizePhoneNumber(
phoneNumber,
application.id,
)

return this.smsService.sendSms(normalizedPhoneNumber, message)
}

async assignApplicationThroughSms(
Expand All @@ -75,7 +80,26 @@ export class SharedTemplateApiService {
assignLink,
)

return this.smsService.sendSms(phoneNumber, message)
const normalizedPhoneNumber = this.normalizePhoneNumber(
phoneNumber,
application.id,
)

return this.smsService.sendSms(normalizedPhoneNumber, message)
}

normalizePhoneNumber(phoneNumber: string, applicationId: string) {
if (phoneNumber.trim().length > 7) {
this.logger.warn(
`Recipient number for application ${applicationId} is longer than 7 characters, attempting to recover`,
)
}
if (phoneNumber.match(/\D/g)) {
this.logger.warn(
`Recipient number for application ${applicationId} contains non-numeric characters, attempting to recover`,
)
}
return phoneNumber.trim().replace(/\D/g, '').slice(-7)
}

async sendEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {
} from '@island.is/clients/work-accident-ver'
import {
getDateAndTime,
getValueList,
mapVictimData,
} from './work-accident-notification.utils'
import { getValueViaPath } from '@island.is/application/core'
import { TemplateApiError } from '@island.is/nest/problem'

@Injectable()
Expand Down Expand Up @@ -57,20 +55,20 @@ export class WorkAccidentNotificationTemplateService extends BaseTemplateApiServ
const answers = application.answers as unknown as WorkAccidentNotification
const payload = {
accidentForCreationDto: {
companySSN: answers.companyInformation.nationalId,
companySSN: answers.basicInformation.nationalId,
sizeOfEnterprise: parseInt(
answers.companyInformation.numberOfEmployees,
answers.basicInformation.numberOfEmployees,
10,
),
nameOfBranchOrDepartment:
answers.companyInformation.nameOfBranch ??
answers.companyInformation.name,
answers.basicInformation.name,
address:
answers.companyInformation.addressOfBranch ??
answers.companyInformation.address,
answers.basicInformation.address,
postcode:
answers.companyInformation.postnumberOfBranch?.slice(0, 3) ??
answers.companyInformation.postnumber.slice(0, 3),
answers.basicInformation.postnumber.slice(0, 3),
workplaceHealthAndSafety:
answers.companyLaborProtection.workhealthAndSafetyOccupation?.map(
(code: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { DrivingLicenseBookUpdateInstructorAnswers } from '@island.is/applicatio
import { BaseTemplateApiService } from '../../base-template-api.service'
import { ApplicationTypes } from '@island.is/application/types'
import { DrivingLicenseBookClientApiFactory } from '@island.is/clients/driving-license-book'
import { TemplateApiError } from '@island.is/nest/problem'
import { coreErrorMessages } from '@island.is/application/core'

@Injectable()
export class DrivingLicenseBookUpdateInstructorService extends BaseTemplateApiService {
Expand All @@ -21,7 +23,13 @@ export class DrivingLicenseBookUpdateInstructorService extends BaseTemplateApiSe
)

if (!overview?.active) {
throw new Error('Did not find active student book')
throw new TemplateApiError(
{
title: coreErrorMessages.drivingLicenseBookActiveBookNotFound,
summary: coreErrorMessages.drivingLicenseBookActiveBookNotFound,
},
400,
)
}

const teacherNationalId = overview.book?.teacherNationalId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"targets": {
"lint": {
"executor": "@nx/eslint:lint"
},
"extract-strings": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/work-accident-notification/src/**/*.{js,ts,tsx}'"
}
}
}
}
Loading

0 comments on commit 1562e0c

Please sign in to comment.