Skip to content

Commit

Permalink
Added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sahalali committed Aug 5, 2024
1 parent bef6c01 commit d0f7dd9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/helper/reconciliation-service.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ReconciliationServiceHelper {

static isQueryByURI(query: string) {
const artsdataIdPattern = "^K[0-9]+-[0-9]+$";
return !!(query.match(artsdataIdPattern) ||
return !!(query?.match(artsdataIdPattern) ||
(this.isValidURI(query) && query.startsWith("http://kg.artsdata.ca/resource/K")));

}
Expand Down
55 changes: 53 additions & 2 deletions src/service/recon/recon.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ describe("Recon Service tests", () => {
]
}
],
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
}, {
Expand All @@ -254,6 +255,7 @@ describe("Recon Service tests", () => {
]
}]
,
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
}, {
Expand All @@ -270,6 +272,7 @@ describe("Recon Service tests", () => {
]
}
],
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
},
Expand All @@ -287,6 +290,7 @@ describe("Recon Service tests", () => {
]
}
],
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
}, {
Expand All @@ -308,6 +312,7 @@ describe("Recon Service tests", () => {
]
}
],
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
},
Expand All @@ -331,17 +336,61 @@ describe("Recon Service tests", () => {
]
}
],
expectedId: "K11-19",
expectedName: "Roy Thomson Hall",
expectedCount: 1
}
}, {
description: "Reconcile Event with Name",
"queries": [
{
"type": "schema:Event",
"limit": 1,
"conditions": [
{
"matchType": "name",
"v": "Matilda - Citadel Theatre"
}
]
}
],
expectedId: "citadeltheatre-com_2018-2019_matilda",
expectedName: "Matilda - Citadel Theatre",
expectedCount: 1
}, {
description: "Reconcile Event with Name and startDate",

"queries": [
{
"type": "schema:Event",
"limit": 1,
"conditions": [
{
"matchType": "name",
"v": "Matilda - Citadel Theatre",
"pid": "string",
"required": true
},
{
"matchType": "property",
"v": "2019-03-17T13:30:00-04:00",
"pid": "schema:startDate",
"required": true
}
]
}
],
expectedId: "citadeltheatre-com_2018-2019_matilda#2019-03-17T133000-0400",
expectedName: "Matilda - Citadel Theatre",
expectedCount: 1
}
];

for (const test of testCases) {
it(test.description, async () => {
const result = await reconService
.reconcileByQueries({ queries: test.queries });
let title = result.results?.[0]?.candidates?.[0]?.name;
const id = result.results?.[0]?.candidates?.[0]?.id;
title = title instanceof String ? title : (title as any)?.values.find((value: {
lang: string;
str: string
Expand All @@ -352,7 +401,9 @@ describe("Recon Service tests", () => {
expect(result.results?.[0].candidates.length).toBe(test.expectedCount);
if (test.duplicateCheck) {
expect(result.results[0]?.candidates?.[0].name === result.results[0]?.candidates?.[1].name).toBeFalsy();

}
if (test.expectedId) {
expect(id).toBe(test.expectedId);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/recon/recon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ReconciliationService {
for (const reconciliationQuery of queries) {
const { type, limit, conditions } = reconciliationQuery;
const { name, propertyConditions } = this._resolveConditions(conditions);
const isQueryByURI = ReconciliationServiceHelper.isQueryByURI(name as string);
const isQueryByURI = !!name && ReconciliationServiceHelper.isQueryByURI(name as string);
const rawSparqlQuery: string = this._getSparqlQuery(name as string, isQueryByURI, type, limit);
const rawSparqlQueryWithPropertyFilters = this._resolvePropertyConditions(rawSparqlQuery, propertyConditions);
const sparqlQuery: string = "query=" + encodeURIComponent(rawSparqlQueryWithPropertyFilters);
Expand Down

0 comments on commit d0f7dd9

Please sign in to comment.