-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIRCSTORE-273 include migration for missing staff slips
* CIRCSTORE-273 include migration for missing staff slips The reference data includes four slips (hold, pick-slip, request-delivery, and transit) but only two (pick-slip, request-delivery) were included in migrations. This meant new tenants would have all four slips available but tenants migrated from previous releases would only have two. Refs CIRCSTORE-273 * clean up unnecessary comments * super helpful if you name your class correctly * CIRCSTORE-273 Change fromModuleVersion, refactor Co-authored-by: Alexander Kurash <[email protected]> (cherry picked from commit 6674432)
- Loading branch information
1 parent
eb5b67e
commit 9e5b54e
Showing
6 changed files
with
118 additions
and
33 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/resources/templates/db_scripts/add_staff_slips_hold_transit.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
INSERT INTO ${myuniversity}_${mymodule}.staff_slips(id, jsonb) VALUES ( | ||
'6a6e72f0-69da-4b4c-8254-7154679e9d88', | ||
jsonb_build_object( | ||
'id', '6a6e72f0-69da-4b4c-8254-7154679e9d88', | ||
'name', 'Hold', | ||
'active', true, | ||
'template', '<p></p>')) ON CONFLICT DO NOTHING; | ||
|
||
INSERT INTO ${myuniversity}_${mymodule}.staff_slips(id, jsonb) VALUES ( | ||
'f838cdaf-555a-473f-abf1-f35ef6ab8ae1', | ||
jsonb_build_object( | ||
'id', 'f838cdaf-555a-473f-abf1-f35ef6ab8ae1', | ||
'name', 'Transit', | ||
'active', true, | ||
'template', '<p></p>')) ON CONFLICT DO NOTHING; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/org/folio/rest/api/migration/StaffSlipsHoldTransitMigrationScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.folio.rest.api.migration; | ||
|
||
import static org.junit.Assert.assertThat; | ||
|
||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.folio.rest.api.StorageTestSuite; | ||
import org.folio.rest.support.JsonResponse; | ||
import org.folio.rest.support.ResponseHandler; | ||
import org.hamcrest.core.Is; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class StaffSlipsHoldTransitMigrationScriptTest extends StaffSlipsMigrationTestBase { | ||
public static final String HOLD_ID = "6a6e72f0-69da-4b4c-8254-7154679e9d88"; | ||
public static final String TRANSIT_ID = "f838cdaf-555a-473f-abf1-f35ef6ab8ae1"; | ||
private static final String MIGRATION_SCRIPT = loadScript("add_staff_slips_hold_transit.sql"); | ||
|
||
@Before | ||
public void beforeEach() throws MalformedURLException { | ||
StorageTestSuite.deleteAll(staffSlipsStorageUrl("")); | ||
} | ||
|
||
@Test | ||
public void canMigrateStaffSlips() throws Exception { | ||
|
||
executeMultipleSqlStatements(MIGRATION_SCRIPT); | ||
|
||
CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>(); | ||
client.get(staffSlipsStorageUrl(""), StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted)); | ||
JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS); | ||
|
||
assertThat(getResponse.getStatusCode(), Is.is(HttpURLConnection.HTTP_OK)); | ||
|
||
JsonArray slipsJsonArray = getResponse.getJson().getJsonArray("staffSlips"); | ||
|
||
JsonObject hold = getRecordById(slipsJsonArray, HOLD_ID); | ||
JsonObject transit = getRecordById(slipsJsonArray, TRANSIT_ID); | ||
|
||
assertStaffSlip(hold, HOLD_ID, "Hold"); | ||
assertStaffSlip(transit, TRANSIT_ID, "Transit"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/org/folio/rest/api/migration/StaffSlipsMigrationTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.folio.rest.api.migration; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.rest.api.StorageTestSuite; | ||
|
||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
public class StaffSlipsMigrationTestBase extends MigrationTestBase { | ||
public static final String TEMPLATE = "<p></p>"; | ||
|
||
JsonObject getRecordById(JsonArray collection, String id) { | ||
return collection.stream() | ||
.map(index -> (JsonObject) index) | ||
.filter(request -> StringUtils.equals(request.getString("id"), id)) | ||
.findFirst().orElse(null); | ||
} | ||
|
||
void assertStaffSlip(JsonObject staffSlip, String expectedId, | ||
String expectedName) { | ||
|
||
assertThat(staffSlip.getString("id"), is(expectedId)); | ||
assertThat(staffSlip.getString("name"), is(expectedName)); | ||
assertThat(staffSlip.getBoolean("active"), is(true)); | ||
assertThat(staffSlip.getString("template"), is(TEMPLATE)); | ||
} | ||
|
||
URL staffSlipsStorageUrl(String subPath) throws MalformedURLException { | ||
return StorageTestSuite.storageUrl("/staff-slips-storage/staff-slips" + subPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters