Skip to content

Commit

Permalink
feat(fa): Creating changebla month for financial-aid (#14974)
Browse files Browse the repository at this point in the history
* adding sortable feature

* Revert "adding sortable feature"

This reverts commit d9691c5.

* adding more detail for api

* removing white space break just adding html element to the db

* adding applied

* when creating application

* use applied when applied

* creating modal

* wokring onf rontend for update date

* code review

* remvoing unused css

* applied month

* updateing spec

* update from code bunny

* updating test

* remvoing applied

* fixing migration

* test

* trying to make test work

* more test

* trying to get create test to work

* removing test to move on

* using now factory lets go

* testing lint

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
MargretFinnboga and kodiakhq[bot] authored May 30, 2024
1 parent 8d821f4 commit b2d46d9
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class ApplicationModel implements Application {
@Field()
readonly modified!: string

@Field()
readonly applied!: string

@Field()
readonly nationalId!: string

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

module.exports = {
async up(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction(async (t) => {
// Add the new column
await queryInterface.addColumn(
'applications',
'applied',
{
type: Sequelize.DATE,
allowNull: true,
},
{ transaction: t },
)

// Update the applied column with the createdAt date
await queryInterface.sequelize.query(
`
UPDATE applications
SET applied = created;
`,
{ transaction: t },
)

// Change the column to not allow null values if necessary
await queryInterface.changeColumn(
'applications',
'applied',
{
type: Sequelize.DATE,
allowNull: false,
},
{ transaction: t },
)
})
},

async down(queryInterface, Sequelize) {
return queryInterface.sequelize.transaction((t) =>
Promise.all([
queryInterface.removeColumn('applications', 'applied', {
transaction: t,
}),
]),
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { DeductionFactorsModel } from '../deductionFactors'
import { DirectTaxPaymentService } from '../directTaxPayment'
import { DirectTaxPaymentModel } from '../directTaxPayment/models'
import { ChildrenModel, ChildrenService } from '../children'
import { nowFactory } from './factories/date.factory'

interface Recipient {
name: string
Expand Down Expand Up @@ -146,7 +147,7 @@ export class ApplicationService {
spouseNationalId: nationalId,
},
],
created: { [Op.gte]: firstDateOfMonth() },
applied: { [Op.gte]: firstDateOfMonth() },
},
})

Expand Down Expand Up @@ -294,6 +295,7 @@ export class ApplicationService {

const appModel = await this.applicationModel.create({
...application,
applied: nowFactory(),
nationalId: application.nationalId || user.nationalId,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const nowFactory = () => new Date()
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export class ApplicationModel extends Model {
@ApiProperty()
modified: Date

@Column({
type: DataType.DATE,
allowNull: false,
})
@ApiProperty()
applied: Date

@Column({
type: DataType.STRING,
allowNull: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EmailService } from '@island.is/email-service'
import {
ApplicationState,
ChildrenAid,
Employment,
FamilyStatus,
FileType,
Expand All @@ -21,6 +22,8 @@ import { ApplicationModel } from '../models/application.model'
import { createTestingApplicationModule } from './createTestingApplicationModule'
import { DirectTaxPaymentService } from '../../directTaxPayment'
import { ChildrenService } from '../../children'
import { nowFactory } from '../factories/date.factory'
jest.mock('../factories/date.factory')

interface Then {
result: ApplicationModel
Expand Down Expand Up @@ -80,6 +83,7 @@ describe('ApplicationController - Create', () => {
describe('database query', () => {
let mockCreate: jest.Mock
let mockFindOne: jest.Mock
const date = new Date()

const user: User = {
nationalId: '0000000000',
Expand Down Expand Up @@ -121,6 +125,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}

beforeEach(async () => {
Expand All @@ -129,13 +135,17 @@ describe('ApplicationController - Create', () => {
const mockFindApplication = mockApplicationModel.findOne as jest.Mock
mockFindApplication.mockReturnValueOnce(null)

const mockToday = nowFactory as jest.Mock
mockToday.mockReturnValueOnce(date)

await givenWhenThen(user, application)
})

it('should call create on model with application', () => {
expect(mockCreate).toHaveBeenCalledWith({
nationalId: user.nationalId,
...application,
applied: date,
})
})

Expand All @@ -150,7 +160,7 @@ describe('ApplicationController - Create', () => {
spouseNationalId: user.nationalId,
},
],
created: { [Op.gte]: firstDateOfMonth() },
applied: { [Op.gte]: firstDateOfMonth() },
},
})
})
Expand Down Expand Up @@ -201,6 +211,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}

const municipality: Municipality = {
Expand All @@ -213,12 +225,14 @@ describe('ApplicationController - Create', () => {
individualAid: undefined,
cohabitationAid: undefined,
usingNav: false,
childrenAid: ChildrenAid.NOTDEFINED,
}

const appModel = {
id,
state: application.state,
created: new Date(),
applied: new Date(),
email: application.email,
}

Expand Down Expand Up @@ -323,6 +337,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: null,
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}

const municipality: Municipality = {
Expand All @@ -335,12 +351,14 @@ describe('ApplicationController - Create', () => {
individualAid: undefined,
cohabitationAid: undefined,
usingNav: false,
childrenAid: ChildrenAid.NOTDEFINED,
}

const appModel = {
id,
state: application.state,
created: new Date(),
applied: new Date(),
email: application.email,
spouseEmail: application.spouseEmail,
spouseName: application.spouseName,
Expand Down Expand Up @@ -437,12 +455,15 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}

const appModel = {
id,
state: application.state,
created: new Date(),
applied: new Date(),
email: application.email,
}

Expand Down Expand Up @@ -532,6 +553,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: '',
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}
const user: User = {
nationalId: '0000000000',
Expand All @@ -542,6 +565,7 @@ describe('ApplicationController - Create', () => {
id,
state: application.state,
created: new Date(),
applied: new Date(),
email: application.email,
}

Expand Down Expand Up @@ -623,13 +647,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
}

const appModel = {
id,
state: application.state,
created: new Date(),
email: application.email,
children: [],
childrenComment: '',
}

beforeEach(async () => {
Expand Down Expand Up @@ -687,6 +706,8 @@ describe('ApplicationController - Create', () => {
applicationSystemId: '',
nationalId: user.nationalId,
spouseHasFetchedDirectTaxPayment: false,
children: [],
childrenComment: '',
}

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ApplicationController - Get current application', () => {
spouseNationalId: user.nationalId,
},
],
created: { [Op.gte]: firstDateOfMonth() },
applied: { [Op.gte]: firstDateOfMonth() },
},
})
})
Expand Down
3 changes: 3 additions & 0 deletions apps/financial-aid/web-veita/graphql/sharedGql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ApplicationQuery = gql`
applicationSystemId
nationalId
created
applied
modified
name
phoneNumber
Expand Down Expand Up @@ -208,6 +209,7 @@ export const ApplicationEventMutation = gql`
nationalId
created
modified
applied
name
phoneNumber
email
Expand Down Expand Up @@ -328,6 +330,7 @@ export const UpdateApplicationMutation = gql`
nationalId
created
modified
applied
name
phoneNumber
email
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { style } from '@vanilla-extract/css'

export const modal = style({
display: 'block',
width: '100%',
maxWidth: '440px',
boxShadow: '0px 8px 32px rgba(0, 0, 0, 0.08)',
borderRadius: '12px',
})
Loading

0 comments on commit b2d46d9

Please sign in to comment.