Skip to content

Commit

Permalink
Merge pull request #12 from culturecreates/feature/issue-10
Browse files Browse the repository at this point in the history
Feature/issue 10
  • Loading branch information
sahalali authored May 17, 2024
2 parents 2abe61a + da352ec commit 80466d2
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 0 deletions.
117 changes: 117 additions & 0 deletions sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
require 'test_helper'

# StatementsHelper tests for search_cckg() only
class StatementsHelperSearchCckgTest < ActionView::TestCase
tests StatementsHelper

test "search_cckg: should search cckg for uris that match 100%" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should search cckg for uris that match 100%') do
expected = {:data=>[["Place des Arts - Théâtre Maisonneuve", "http://kg.artsdata.ca/resource/K11-11"]]}
actual = search_cckg "Théâtre Maisonneuve", "Place"
assert_equal expected, actual
end
end

test "search_cckg: should search cckg for uris by matching name in substring" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should search cckg for uris by matching name in substring') do
expected = {:data=>[["St. Lawrence Centre for the Arts - Bluma Appel Theatre", "http://kg.artsdata.ca/resource/K11-6"], ["Canadian Stage - Berkeley Street Theatre", "http://kg.artsdata.ca/resource/K11-14"]]}
actual = search_cckg "The locations is in the lovely Bluma Appel Theatre and Berkeley Street Theatre.", "Place"
assert_equal expected, actual
end
end

test "search_cckg: should search cckg for VaughnCo Entertainment presents" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should search cckg for VaughnCo Entertainment presents') do
expected = {data:[["VaughnCo Entertainment", "http://kg.artsdata.ca/resource/K10-148"]]}
actual = search_cckg "VaughnCo Entertainment presents", "Organization"
assert_equal expected, actual
end
end


test "search_cckg: should search cckg for Wajdi Mouawad" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should search cckg for Wajdi Mouawad') do
expected = {data:[["Wajdi Mouawad", "http://kg.artsdata.ca/resource/K12-362"]]}
actual = search_cckg "Wajdi Mouawad", "Person"
assert_equal expected, actual
end
end


test "search_cckg: should search cckg for nowhere" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should search cckg for nowhere') do
expected = {:data=>[]}
actual = search_cckg "Show is at nowhere", "Place"
assert_equal expected, actual
end
end

test "search_cckg: remove duplicates" do
VCR.use_cassette('StatementsHelperSearchCckgTest: remove duplicates') do
expected = {data:[["Canadian Stage - Berkeley Street Theatre", "http://kg.artsdata.ca/resource/K11-14"]]}
actual = search_cckg "The locations is in the lovely Berkeley Street Theatre and Canadian Stage - Berkeley Street Theatre.", "Place"
assert_equal expected, actual
end
end

# Common words: example Person name that is removed "wiL", "http://kg.artsdata.ca/resource/K12-32"
test "search_cckg: should not match names with common words" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should not match names with common words') do
expected = {data:[]}
actual = search_cckg "The word will contains part of a first name.", "Person"
assert_equal expected, actual
end
end

test "search_cckg: should match names with single neutral quote" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should match names with single neutral quote') do
expected = {:data=>[["La P'tite Église (Shippagan)", "http://kg.artsdata.ca/resource/K11-131"]]}
actual = search_cckg "Shippagan 20 h 00 La P'tite Église (Shippagan)", "Place"
assert_equal expected, actual
end
end

test "search_cckg: should match names with single curved quote" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should match names with single curved quote') do
expected = {:data=>[["Emily D’Angelo", "http://kg.artsdata.ca/resource/K12-150"]]}
actual = search_cckg "Emily D’Angelo", "Person"
assert_equal expected, actual
end
end


test "search_cckg: should match names with &" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should match names with &') do
expected = {:data=>[["meagan&amy", "http://kg.artsdata.ca/resource/K10-376"]]}
actual = search_cckg "meagan&amp;amy", "Organization"
assert_equal expected, actual
end
end

test "search_cckg: should match places with title in French" do
VCR.use_cassette('StatementsHelperSearchCckgTest: should match places with title in French') do
expected = {:data=>[["Théâtre Marc Lescarbot", "http://kg.artsdata.ca/resource/K11-133"]]}
actual = search_cckg "Théâtre Marc Lescarbot", "Place"
assert_equal expected, actual
end
end

test "search_cckg: find alternate names" do
VCR.use_cassette('StatementsHelperSearchCckgTest: find alternate names') do
expected = {data:[["Dow Centennial Centre - Shell Theatre", "http://kg.artsdata.ca/resource/K11-64"]]}
actual = search_cckg "Shell Theatre", "Place"
assert_equal expected, actual
end
end


test "search_cckg: find additional type using artsdata" do
VCR.use_cassette('StatementsHelperSearchCckgTest: find additional types') do
expected = {data:[["Dance", "http://kg.artsdata.ca/resource/DancePerformance"]]}
actual = search_cckg("Dance", "EventType")
assert_equal expected, actual
end
end


end
2 changes: 2 additions & 0 deletions src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "./manifest"
export * from "./recon"
export * from "./artsdata"
export * from "./http"
182 changes: 182 additions & 0 deletions src/service/recon/recon.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { Test, TestingModule } from "@nestjs/testing";
import { ReconciliationService, ManifestService, ArtsdataService, HttpService} from "../../service";
import { ManifestController, ReconciliationController } from "../../controller";

describe('Recon Service tests', () => {
let reconService: ReconciliationService;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [ManifestController, ReconciliationController],
providers: [ManifestService, ReconciliationService, ArtsdataService, HttpService]
}).compile();

reconService = app.get<ReconciliationService>(ReconciliationService);
});

describe("Recon API Tests", () => {
jest.setTimeout(200000)
const testCases = [
{
description: "It should search for uris that match 100%",
query: {
q0: {
query: "Théâtre Maisonneuve",
type: "schema:Place",
limit: 1
}
},
expectedName: "Place des Arts - Théâtre Maisonneuve",
expectedCount: 1
},
{
description: "It should search for uris by matching name in substring",
query:{
q0: {
query: "The locations is in the lovely Bluma Appel Theatre and Berkeley Street Theatre.",
type: "schema:Place",
limit: 1
}
},
expectedName: "St. Lawrence Centre for the Arts - Bluma Appel Theatre",
expectedCount: 1

},
{
description: "It should search for VaughnCo Entertainment presents",
query:{
q0: {
query: "VaughnCo Entertainment presents",
type: "schema:Organization",
limit: 1
}
},
expectedName: "VaughnCo Entertainment",
expectedCount: 1
},
{
description: "It should search for Wajdi Mouawad",
query:{
q0: {
query: "Wajdi Mouawad",
type: "schema:Person",
limit: 1
}
},
expectedName: "Wajdi Mouawad",
expectedCount: 1
},
{
description: "It should search for nowhere",
query:{
q0: {
query: "Show is nowhere",
type: "schema:Place",
limit: 1
}
},
expectedName: undefined,
expectedCount: 0
},
{
description: "It should remove duplicates",
query:{
q0: {
query: "The locations is in the lovely Berkeley Street Theatre and Canadian Stage - Berkeley Street Theatre.",
type: "schema:Place",
limit: 2
}
},
expectedName: "Canadian Stage - Berkeley Street Theatre",
expectedCount: 2,
duplicateCheck: true
},
{
description: "It should match names with single neutral quote",
query:{
q0: {
query: "Shippagan 20 h 00 La P'tite Église (Shippagan)",
type: "schema:Place",
limit: 1
}
},
expectedName: "La P'tite Église (Shippagan)",
expectedCount: 1
},
{
description: "It should match names with single curved quote",
query:{
q0: {
query: "Emily D’Angelo",
type: "schema:Person",
limit: 1
}
},
expectedName: "Emily D’Angelo",
expectedCount: 1
},
{
description: "It should match names with &",
query:{
q0: {
query: "meagan&amp;amy",
type: "schema:Organization",
limit: 1
}
},
expectedName: "meagan&amy",
expectedCount: 1
},
{
description: "It should match places with title in French",
query:{
q0: {
query: "Théâtre Marc Lescarbot",
type: "schema:Place",
limit: 1
}
},
expectedName: "le Marc Lescarbot (Pointe-de-l’église)",
expectedCount: 1
},
{
description: "It should find alternate names",
query:{
q0: {
query: "Shell Theatre",
type: "schema:Place",
limit: 1
}
},
expectedName: "Dow Centennial Centre - Shell Theatre",
expectedCount: 1
},
{
description: "It should find additional type using artsdata",
query:{
q0: {
query: "Dance",
type: "ado:EventType",
limit: 1
}
},
expectedName: "Dance",
expectedCount: 1
}
]

for(const test of testCases){
it(test.description, async () => {
const result = await reconService.reconcileByQueries(test.query);
expect(result.q0?.result[0]?.name).toBe(test.expectedName);
expect(result.q0?.result?.length).toBe(test.expectedCount);
if(test.duplicateCheck){
expect(result.q0.result[0].name === result.q0.result[1].name).toBeFalsy();
}
})
}

})


});

0 comments on commit 80466d2

Please sign in to comment.