Skip to content

Commit

Permalink
MODLD-599: LCCN pattern validation (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
askhat-abishev authored Nov 28, 2024
1 parent 4e42554 commit ee4f166
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: LCCN pattern validation

Background:
* url baseUrl
* call login testUser
* def testUserHeaders = { 'Content-Type': 'application/json', 'x-okapi-token': '#(okapitoken)', 'Accept': '*/*' }
* configure headers = testUserHeaders

Scenario: Create resources with enabled validation and then repeat with disabled validation
# Step 1: Enable validation
* def getSpecificationsCall = call getSpecifications { profileParam: "bibliographic", familyParam: "MARC" }
* def specificationId = getSpecificationsCall.response.specifications[0].id
* def getRulesCall = call getRules { specificationId: '#(specificationId)' }
* def ruleId = karate.filter(getRulesCall.response.rules, function (rule) { return rule.code === "invalidLccnSubfieldValue" })[0].id
* call patchRule { specificationId: '#(specificationId)', ruleId: '#(ruleId)', isEnabled: true }

# Step 2: Create a work
* def workRequest = read('samples/work-request.json')
* def postWorkCall = call postResource { resourceRequest: '#(workRequest)' }
* def workId = postWorkCall.response.resource['http://bibfra.me/vocab/lite/Work'].id

# Step 3: Create valid instance
* def validInstanceRequest = read('samples/valid-instance-request.json')
* call postResource { resourceRequest: '#(validInstanceRequest)' }

# Step 4: Fail to create invalid instance
* def invalidInstanceRequest = read('samples/invalid-instance-request.json')
Given path 'linked-data/resource'
And request invalidInstanceRequest
When method POST
Then status 400
And match $.errors[0].code == "lccn_does_not_match_pattern"

# Step 5: Disable validation
* call patchRule { specificationId: '#(specificationId)', ruleId: '#(ruleId)', isEnabled: false }

# Step 6: Create invalid instance
* call postResource { resourceRequest: '#(invalidInstanceRequest)' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"resource":{
"http://bibfra.me/vocab/lite/Instance":{
"http://bibfra.me/vocab/marc/title":[
{
"http://bibfra.me/vocab/marc/Title":{
"http://bibfra.me/vocab/marc/mainTitle":[
"Invalid instance main title"
]
}
}
],
"http://library.link/vocab/map":[
{
"http://library.link/identifier/LCCN":{
"http://bibfra.me/vocab/lite/name":[
"n!1234567890"
],
"http://bibfra.me/vocab/marc/status":[
{
"http://bibfra.me/vocab/lite/label":[
"current"
],
"http://bibfra.me/vocab/lite/link":[
"http://id.loc.gov/vocabulary/mstatus/current"
]
}
]
}
}
],
"_workReference":[
{
"id": "#(workId)"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"resource":{
"http://bibfra.me/vocab/lite/Instance":{
"http://bibfra.me/vocab/marc/title":[
{
"http://bibfra.me/vocab/marc/Title":{
"http://bibfra.me/vocab/marc/mainTitle":[
"Valid instance main title"
]
}
}
],
"http://library.link/vocab/map":[
{
"http://library.link/identifier/LCCN":{
"http://bibfra.me/vocab/lite/name":[
" 1234567890"
],
"http://bibfra.me/vocab/marc/status":[
{
"http://bibfra.me/vocab/lite/label":[
"current"
],
"http://bibfra.me/vocab/lite/link":[
"http://id.loc.gov/vocabulary/mstatus/current"
]
}
]
}
}
],
"_workReference":[
{
"id": "#(workId)"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resource":{
"http://bibfra.me/vocab/lite/Work":{
"http://bibfra.me/vocab/marc/title":[
{
"http://bibfra.me/vocab/marc/Title":{
"http://bibfra.me/vocab/marc/mainTitle":[
"Work main title"
]
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: CRUD operations on a specifications
Background:
* url baseUrl

@getSpecifications
Scenario: Get a collection of specifications
Given path 'specification-storage/specifications'
And param profile = profileParam
And param family = familyParam
When method Get
Then status 200
* def response = $

@getRules
Scenario: Get a collection of rules of a specification
Given path 'specification-storage/specifications/' + specificationId + '/rules'
When method Get
Then status 200
* def response = $

@patchRule
Scenario: Update a specification rule
Given path 'specification-storage/specifications/' + specificationId + '/rules/' + ruleId
And request
"""
{
"enabled": "#(isEnabled)"
}
"""
When method Patch
Then status 204
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Feature: mod-linked-data integration tests
| 'mod-source-record-storage' |
| 'mod-quick-marc' |
| 'mod-linked-data' |
| 'mod-record-specifications' |

* table userPermissions
| name |
Expand Down Expand Up @@ -51,6 +52,9 @@ Feature: mod-linked-data integration tests
| 'inventory-storage.authority-source-files.item.post' |
| 'browse.authorities.collection.get' |
| 'source-storage.records.formatted.item.get' |
| 'specification-storage.specifications.collection.get' |
| 'specification-storage.specification.rules.collection.get' |
| 'specification-storage.specification.rules.item.patch' |

Scenario: create tenant and users for testing
Given call read('classpath:common/setup-users.feature')
3 changes: 3 additions & 0 deletions mod-linked-data/src/main/resources/karate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function fn() {
getResourceSupportCheck: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@getResourceSupportCheck'),
getResourcePreview: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@getResourcePreview'),
postImport: karate.read('classpath:citation/mod-linked-data/features/util/crud-resource.feature@postImport'),
getSpecifications: karate.read('classpath:citation/mod-linked-data/features/util/crud-specifications.feature@getSpecifications'),
getRules: karate.read('classpath:citation/mod-linked-data/features/util/crud-specifications.feature@getRules'),
patchRule: karate.read('classpath:citation/mod-linked-data/features/util/crud-specifications.feature@patchRule'),

// define global functions
uuid: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ void updateAuthority() {
void importBibRecordFromSrsToLinkedData() {
runFeatureTest("import-bib/import-bib.feature");
}

@Test
void lccnPatternValidation() {
runFeatureTest("lccn-pattern-validation/lccn-pattern-validation.feature");
}
}

0 comments on commit ee4f166

Please sign in to comment.