-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a88424
commit 59bc8d7
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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,12 @@ | ||
/* eslint-disable no-unused-vars */ | ||
export enum SearchScope { | ||
ArtMuseum = 'artmuseum', | ||
BestBets = 'best-bet', | ||
Catalog = 'catalog', | ||
Dpul = 'dpul', | ||
FindingAids = 'findingaids', | ||
LibAnswers = 'libanswers', | ||
LibGuides = 'libguides', | ||
LibraryDatabases = 'database', | ||
PulMap = 'pulmap' | ||
} |
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,8 @@ | ||
export interface SearchResult { | ||
title: string | ||
url: string | ||
id: string | ||
type?: string | ||
publisher?: string | ||
other_fields: any | ||
} |
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,7 @@ | ||
import { SearchResult } from "./SearchResult" | ||
|
||
export interface SearchResults { | ||
number: number | ||
more: string | ||
results: SearchResult[] | ||
} |
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,23 @@ | ||
import { describe, test, expect } from "vitest"; | ||
import { SearchService } from "./SearchService"; | ||
import { SearchScope } from "../enums/SearchScope"; | ||
|
||
describe('SearchService', () => { | ||
describe('catalogResults()', () => { | ||
test('it includes number of results', async () => { | ||
const service = new SearchService(); | ||
const results = await service.results(SearchScope.Catalog, 'donkeys'); | ||
expect(results.number).toEqual(23_182); | ||
}); | ||
test('it includes more link', async () => { | ||
const service = new SearchService(); | ||
const results = await service.results(SearchScope.Catalog, 'walrus'); | ||
expect(results.more).toEqual('https://example.com'); | ||
}); | ||
test('it has three results', async() => { | ||
const service = new SearchService(); | ||
const results = await service.results(SearchScope.Catalog, 'walrus'); | ||
expect(results.results.length).toEqual(3); | ||
}) | ||
}); | ||
}); |
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,36 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import { SearchResults } from "../interfaces/SearchResults"; | ||
|
||
export class SearchService { | ||
results(service: string, query: string): Promise<SearchResults> { | ||
return new Promise((resolve) => { | ||
resolve({ | ||
number: 23_182, | ||
more: 'https://example.com', | ||
results: [ | ||
{ | ||
title: 'Potato', | ||
publisher: 'Potato company', | ||
id: '123', | ||
type: 'Book', | ||
url: 'https://catalog.princeton.edu/catalog/99125129988006421', | ||
other_fields: {} | ||
}, { | ||
title: 'Cheese', | ||
publisher: 'Cheese company', | ||
id: '456', | ||
type: 'Audio', | ||
url: 'https://catalog.princeton.edu/catalog/99125192574206421', | ||
other_fields: {} | ||
}, { | ||
title: 'Salmon', | ||
id: '789', | ||
type: 'Coin', | ||
url: 'https://catalog.princeton.edu/catalog/99125150851306421', | ||
other_fields: {} | ||
}, | ||
] | ||
}) | ||
}); | ||
} | ||
} |