Skip to content

Commit

Permalink
Update case.transformer.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
unakb committed Oct 24, 2024
1 parent 2a7c90b commit f4020cd
Showing 1 changed file with 21 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,107 +540,56 @@ describe('getAppealInfo', () => {
expect(appealInfo).toEqual({})
})

it('should return correct appeal info when ruling date is provided', () => {
it('should return not return appealedDate if case has not been appealed', () => {
const rulingDate = new Date().toISOString()
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
appealState: CaseAppealState.APPEALED,
accusedAppealDecision: CaseAppealDecision.APPEAL,
prosecutorAppealDecision: CaseAppealDecision.NOT_APPLICABLE,
appealState: undefined,
accusedAppealDecision: CaseAppealDecision.POSTPONE,
prosecutorAppealDecision: CaseAppealDecision.POSTPONE,
accusedPostponedAppealDate: '2022-06-15T19:50:08.033Z',
appealReceivedByCourtDate: '2021-06-15T19:50:08.033Z',
prosecutorPostponedAppealDate: '2022-06-15T19:50:08.033Z',
} as Case

const appealInfo = getAppealInfo(theCase)

expect(appealInfo).toEqual({
canBeAppealed: false,
hasBeenAppealed: true,
appealedByRole: UserRole.DEFENDER,
appealedDate: '2022-06-15T19:50:08.033Z',
canBeAppealed: true,
hasBeenAppealed: false,
appealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
statementDeadline: '2021-06-16T19:50:08.033Z',
canDefenderAppeal: false,
canProsecutorAppeal: false,
})
})

const rulingDate = new Date().toISOString()

Object.values(CaseAppealDecision).forEach((decision) => {
const expected =
decision === CaseAppealDecision.POSTPONE ||
decision === CaseAppealDecision.NOT_APPLICABLE

test(`canProsecutorAppeal for appeal decision ${decision} should return ${expected}`, () => {
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
prosecutorAppealDecision: decision,
} as Case

const appealInfo = getAppealInfo(theCase)

expect(appealInfo).toHaveProperty('canProsecutorAppeal', expected)
})
})

Object.values(CaseAppealDecision).forEach((decision) => {
const expected =
decision === CaseAppealDecision.POSTPONE ||
decision === CaseAppealDecision.NOT_APPLICABLE

test(`canDefenderAppeal for appeal decision ${decision} should return ${expected}`, () => {
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
accusedAppealDecision: decision,
} as Case

const appealInfo = getAppealInfo(theCase)

expect(appealInfo).toHaveProperty('canDefenderAppeal', expected)
canDefenderAppeal: true,
canProsecutorAppeal: true,
})
})
})

describe('getAppealInfo', () => {
it('should return empty appeal info when ruling date is not provided', () => {
// Arrange
const theCase = { type: CaseType.CUSTODY } as Case

// Act
const appealInfo = getAppealInfo(theCase)

// Assert
expect(appealInfo).toEqual({})
})

it('should return not return appealedDate if case has not been appealed', () => {
it('should return correct appeal info when ruling date is provided', () => {
const rulingDate = new Date().toISOString()
const theCase = {
type: CaseType.CUSTODY,
rulingDate,
appealState: undefined,
accusedAppealDecision: CaseAppealDecision.POSTPONE,
prosecutorAppealDecision: CaseAppealDecision.POSTPONE,
appealState: CaseAppealState.APPEALED,
accusedAppealDecision: CaseAppealDecision.APPEAL,
prosecutorAppealDecision: CaseAppealDecision.NOT_APPLICABLE,
accusedPostponedAppealDate: '2022-06-15T19:50:08.033Z',
prosecutorPostponedAppealDate: '2022-06-15T19:50:08.033Z',
appealReceivedByCourtDate: '2021-06-15T19:50:08.033Z',
} as Case

const appealInfo = getAppealInfo(theCase)

expect(appealInfo).toEqual({
canBeAppealed: true,
hasBeenAppealed: false,
canBeAppealed: false,
hasBeenAppealed: true,
appealedByRole: UserRole.DEFENDER,
appealedDate: '2022-06-15T19:50:08.033Z',
appealDeadline: new Date(
new Date(rulingDate).setDate(new Date(rulingDate).getDate() + 3),
).toISOString(),
canDefenderAppeal: true,
canProsecutorAppeal: true,
statementDeadline: '2021-06-16T19:50:08.033Z',
canDefenderAppeal: false,
canProsecutorAppeal: false,
})
})

Expand Down

0 comments on commit f4020cd

Please sign in to comment.