Skip to content

Commit

Permalink
clear cache before retreiving
Browse files Browse the repository at this point in the history
  • Loading branch information
danPudwellOpencast committed Sep 26, 2017
1 parent 68c84c0 commit bce2c6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/services/SummaryReturnsService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ trait SummaryReturnsService {
}

for {
_ <- dataCacheConnector.clearCache()
cachedReturns <- dataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](RetrieveReturnsResponseId)
summaryReturns: SummaryReturnsModel <- {
cachedReturns match {
Expand Down
7 changes: 7 additions & 0 deletions test/services/SummaryReturnsServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc

"connector returns OK as response, then Return SummaryReturnsModel after filtering out errant period" in {

when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(None))
when(mockDataCacheConnector.saveFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId), Matchers.any())(Matchers.any(), Matchers.any(), Matchers.any()))
Expand All @@ -95,6 +96,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc

"connector returns NON-OK as response, then throw exception" in {

when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(None))
when(mockDataCacheConnector.saveFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId), Matchers.any())(Matchers.any(), Matchers.any(), Matchers.any()))
Expand All @@ -113,6 +115,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc

"connector returns OK as response, then Return SummaryReturnsModel" in {

when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
val dataCached = data.copy(allReturns = data.allReturns.map(_.copy(draftReturns = Nil)))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(Some(dataCached)))
Expand All @@ -125,6 +128,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc

"connector returns NON-OK as response, then throw exception" in {

when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
val dataCached = data.copy(allReturns = data.allReturns.map(_.copy(draftReturns = Nil)))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(Some(dataCached)))
Expand All @@ -151,6 +155,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc
val json = Json.toJson(data)

"return Some(PeriodSummaryReturns), if that period is found in SummaryReturnsModel" in {
when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
when(mockDataCacheConnector.saveFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId), Matchers.any())(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(data))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
Expand All @@ -163,6 +168,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc
}

"return None, if that period is not-found in SummaryReturnsModel" in {
when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
when(mockDataCacheConnector.fetchAndGetFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(None))
when(mockDataCacheConnector.saveFormData[SummaryReturnsModel](Matchers.eq(RetrieveReturnsResponseId), Matchers.any())(Matchers.any(), Matchers.any(), Matchers.any()))
Expand All @@ -187,6 +193,7 @@ class SummaryReturnsServiceSpec extends PlaySpec with OneServerPerSuite with Moc
val pastReturnDetails = Seq(prevReturn)

"save and return past submitted liabilities for a valid user" in {
when(mockDataCacheConnector.clearCache()).thenReturn(Future.successful(HttpResponse(200)))
when(mockDataCacheConnector.fetchAndGetFormData[PreviousReturns](Matchers.eq(RetrieveReturnsResponseId))(Matchers.any(), Matchers.any(), Matchers.any()))
.thenReturn(Future.successful(None))
when(mockAtedConnector.getFullSummaryReturns(Matchers.any(), Matchers.any())).thenReturn(Future.successful(HttpResponse(OK, Some(json1))))
Expand Down

0 comments on commit bce2c6d

Please sign in to comment.