Skip to content

Commit

Permalink
Story/ccls-1998_2013_15 opponents endpoints (#25)
Browse files Browse the repository at this point in the history
* story(ccls-1998): add opponent endpoints

* story(ccls-1998): correct integration test sql

* story(ccls-1998): correct integration tests

* story(ccls-1998): remove boolean defaults
  • Loading branch information
porritta authored Jan 26, 2024
1 parent 6e03a24 commit 0a51d12
Show file tree
Hide file tree
Showing 22 changed files with 1,031 additions and 158 deletions.
136 changes: 135 additions & 1 deletion caab-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ paths:
$ref: "#/components/schemas/priorAuthority"
responses:
'201':
description: 'Case added successfully'
description: 'Prior Authority added successfully'
'400':
description: 'Bad request'
'401':
Expand Down Expand Up @@ -941,6 +941,138 @@ paths:
'500':
description: 'Internal server error'

/applications/{id}/opponents:
get:
tags:
- opponents
summary: 'Get an application''s opponents'
operationId: 'getApplicationOpponents'
parameters:
- name: 'id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
example: '1234567890'
responses:
'200':
description: 'Successful operation'
content:
application/json:
schema:
type: 'array'
items:
$ref: "#/components/schemas/opponent"
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
post:
tags:
- opponents
summary: 'Add an opponent to an application'
operationId: 'addApplicationOpponent'
parameters:
- name: 'id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
- name: 'Caab-User-Login-Id'
in: header
required: true
schema:
type: 'string'
example: '[email protected]'
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/opponent"
responses:
'201':
description: 'Opponent added successfully'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
/opponents/{opponent-id}:
delete:
tags:
- opponents
summary: 'Remove an opponent'
operationId: 'removeOpponent'
parameters:
- name: 'opponent-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
- name: 'Caab-User-Login-Id'
in: header
required: true
schema:
type: 'string'
example: '[email protected]'
responses:
'204':
description: 'No Content'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'
patch:
tags:
- opponents
summary: 'Update an opponent'
operationId: 'updateOpponent'
parameters:
- name: 'opponent-id'
in: 'path'
required: true
schema:
type: 'integer'
format: 'int64'
- name: 'Caab-User-Login-Id'
in: header
required: true
schema:
type: 'string'
example: '[email protected]'
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/opponent"
responses:
'200':
description: 'Opponent updated successfully'
'400':
description: 'Bad request'
'401':
description: 'Unauthorized'
'404':
description: 'Not found'
'500':
description: 'Internal server error'

components:
schemas:
intDisplayValue:
Expand Down Expand Up @@ -1253,6 +1385,8 @@ components:
opponent:
type: 'object'
properties:
id:
type: 'integer'
ebs_id:
type: 'string'
type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import uk.gov.laa.ccms.caab.model.BaseApplication;
import uk.gov.laa.ccms.caab.model.BaseClient;
import uk.gov.laa.ccms.caab.model.LinkedCase;
import uk.gov.laa.ccms.caab.model.Opponent;
import uk.gov.laa.ccms.caab.model.PriorAuthority;
import uk.gov.laa.ccms.caab.model.Proceeding;
import uk.gov.laa.ccms.caab.model.ScopeLimitation;
Expand Down Expand Up @@ -190,6 +191,12 @@ private void nullModelIds(ApplicationDetail applicationDetail) {
priorAuthority.setId(null);
}
}

if (applicationDetail.getOpponents() != null) {
for (uk.gov.laa.ccms.caab.model.Opponent opponent : applicationDetail.getOpponents()) {
opponent.setId(null);
}
}
}

/**
Expand Down Expand Up @@ -562,6 +569,72 @@ public void updateClient() throws IOException {
assertEquals(baseClient.getSurname(), applicationDetail.getClient().getSurname());
}




@Test
@Sql(scripts = {"/sql/application_insert.sql",})
public void addOpponentToApplication() throws IOException {
Long applicationId = 41L;

Opponent opponent = loadObjectFromJson("/json/opponent_new.json", Opponent.class);

ResponseEntity<Void> response = applicationController.addApplicationOpponent(applicationId, caabUserLoginId, opponent);

assertEquals(HttpStatus.CREATED, response.getStatusCode());
}

@Test
@Sql(scripts = {"/sql/application_insert.sql", "/sql/opponent_insert.sql"})
public void updateOpponentInApplication() throws IOException {
Long opponentId = 3L;

Opponent updatedOpponent = loadObjectFromJson("/json/opponent_new.json", Opponent.class);

ResponseEntity<Void> response = applicationController.updateOpponent(opponentId, caabUserLoginId, updatedOpponent);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}


@Test
@Sql(scripts = {
"/sql/application_insert.sql",
"/sql/opponent_insert.sql"})
public void getOpponentsForApplication() {
Long applicationId = 41L;

ResponseEntity<List<Opponent>> responseEntity = applicationController.getApplicationOpponents(applicationId);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<Opponent> opponents = responseEntity.getBody();
assertFalse(opponents.isEmpty());
}

@Test
@Sql(scripts = {
"/sql/application_insert.sql",
"/sql/opponent_insert.sql"})
public void removeOpponentFromApplication() {
Long caseRef = 41L;
Long opponentRef = 3L;

ResponseEntity<Void> response = applicationController.removeOpponent(
opponentRef, caabUserLoginId);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());

ResponseEntity<List<Opponent>> responseEntity = applicationController.getApplicationOpponents(
caseRef);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertNotNull(responseEntity.getBody());

List<Opponent> opponents = responseEntity.getBody();
assertTrue(opponents.isEmpty());
}

/**
* Assert that the audit trail is set correctly in the object. Uses reflection to navigate the
* auditTrailMethod path and assert that the audit trail is set correctly.
Expand Down
Loading

0 comments on commit 0a51d12

Please sign in to comment.