Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-11811 Merge service changes #2265

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.pay.adminusers.expungeandarchive.resource;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Inject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private int archiveServices() {

ZonedDateTime skipCheckingUntilDate = calculateSkipCheckingForArchivalUntilDate(serviceEntity, lastTransactionDateForService);
serviceEntity.setSkipCheckingForArchivalUntilDate(skipCheckingUntilDate);
serviceDao.merge(serviceEntity);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ExpungeAndArchiveHistoricalDataResourceIT extends IntegrationTest {
.build();

LedgerStub ledgerStub;

@BeforeEach
void setUp() {
databaseHelper.truncateAllData();
Expand Down Expand Up @@ -197,6 +197,50 @@ void shouldNotArchiveServicesWithTransactionsWithInConfiguredNumberOfDays() thro
);
}

@Test
void shouldSet_FirstCheckedForArchivalDate_And_SkipCheckingForArchivalUntilDate_WhenServicesAreNotArchived() throws JsonProcessingException {
Service serviceWithoutCreatedDateOrTransactions = serviceDbFixture(databaseHelper)
.withCreatedDate(null)
.withGatewayAccountIds(valueOf(nextInt()))
.insertService();
Service serviceWithoutCreatedDateAndSomeTransactions = serviceDbFixture(databaseHelper)
.withCreatedDate(null)
.withGatewayAccountIds(valueOf(nextInt()))
.insertService();

LedgerTransaction ledgerTransaction = aLedgerTransactionFixture()
.withCreatedDate(now.minusDays(4))
.build();
LedgerSearchTransactionsResponse searchTransactionsResponse = aLedgerSearchTransactionsResponseFixture()
.withTransactionList(List.of(ledgerTransaction))
.build();
LedgerSearchTransactionsResponse searchTransactionsResponseWitNoResults = aLedgerSearchTransactionsResponseFixture()
.withTransactionList(List.of(ledgerTransaction))
.build();

ledgerStub.returnLedgerTransactionsForSearch(serviceWithoutCreatedDateOrTransactions.getGatewayAccountIds().get(0), searchTransactionsResponseWitNoResults);
ledgerStub.returnLedgerTransactionsForSearch(serviceWithoutCreatedDateAndSomeTransactions.getGatewayAccountIds().get(0), searchTransactionsResponse);

givenSetup().when()
.contentType(JSON)
.accept(JSON)
.post("v1/tasks/expunge-and-archive-historical-data")
.then()
.statusCode(200);

Map<String, Object> serviceAttributes = databaseHelper.findServiceByExternalId(serviceWithoutCreatedDateOrTransactions.getExternalId()).get(0);
assertServiceNotArchived(serviceAttributes);

serviceAttributes = databaseHelper.findServiceByExternalId(serviceWithoutCreatedDateAndSomeTransactions.getExternalId()).get(0);
assertServiceNotArchived(serviceAttributes);
}

private void assertServiceNotArchived(Map<String, Object> serviceAttributes) {
assertThat(serviceAttributes.get("archived"), is(false));
assertThat(serviceAttributes.get("first_checked_for_archival_date"), is(notNullValue()));
assertThat(serviceAttributes.get("skip_checking_for_archival_until_date"), is(notNullValue()));
}

private User insertUser(ZonedDateTime createdDate, ZonedDateTime lastLoggedInAt) {
return userDbFixture(databaseHelper)
.withCreatedAt(createdDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void shouldNotArchiveService_WhenTheLastTransactionDateIsAfterTheServicesEligibl
assertFalse(serviceEntity.isArchived());
assertThat(serviceEntity.getFirstCheckedForArchivalDate(), is(systemDate.withZoneSameInstant(UTC)));
assertThat(serviceEntity.getSkipCheckingForArchivalUntilDate(), is(systemDate.plusDays(8)));
verifyNoMoreInteractions(mockServiceDao);
verify(mockServiceDao).merge(serviceEntity);
}

@Test
Expand All @@ -321,7 +321,7 @@ void shouldNotArchiveService_WhenTheFirstCheckedForArchivalDateIsAfterTheService
assertFalse(serviceEntity.isArchived());
assertThat(serviceEntity.getFirstCheckedForArchivalDate(), is(systemDate));
assertThat(serviceEntity.getSkipCheckingForArchivalUntilDate(), is(systemDate.plusDays(7)));
verifyNoMoreInteractions(mockServiceDao);
verify(mockServiceDao).merge(serviceEntity);
}

@Test
Expand All @@ -343,7 +343,7 @@ void shouldNotSetFirstCheckedForArchivalDateIfItIsAlreadySet() {

assertFalse(serviceEntity.isArchived());
assertThat(serviceEntity.getFirstCheckedForArchivalDate().toString(), is("2021-01-01T10:15:30Z"));
verifyNoMoreInteractions(mockServiceDao);
verify(mockServiceDao).merge(serviceEntity);
}

@Test
Expand All @@ -367,7 +367,7 @@ void shouldNotArchiveServiceWithoutTransactionsAndCreatedIsAfterTheServicesEligi

assertFalse(serviceEntity.isArchived());
assertThat(serviceEntity.getSkipCheckingForArchivalUntilDate(), is(systemDate.plusDays(7)));
verifyNoMoreInteractions(mockServiceDao);
verify(mockServiceDao).merge(serviceEntity);
}

@Test
Expand All @@ -393,7 +393,7 @@ void shouldNotArchiveService_WhenLedgerReturnsNoTransactions_AndCreatedDateOrFir
assertFalse(serviceEntity.isArchived());
assertThat(serviceEntity.getFirstCheckedForArchivalDate(), is(systemDate.withZoneSameInstant(UTC)));
assertThat(serviceEntity.getSkipCheckingForArchivalUntilDate(), is(systemDate.plusDays(7)));
verifyNoMoreInteractions(mockServiceDao);
verify(mockServiceDao).merge(serviceEntity);
}
}
}