Skip to content

Commit

Permalink
Add fake data service
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed Oct 6, 2023
1 parent 1a88424 commit 59bc8d7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/enums/SearchScope.ts
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'
}
8 changes: 8 additions & 0 deletions src/interfaces/SearchResult.ts
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
}
7 changes: 7 additions & 0 deletions src/interfaces/SearchResults.ts
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[]
}
23 changes: 23 additions & 0 deletions src/services/SearchService.test.ts
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);
})
});
});
36 changes: 36 additions & 0 deletions src/services/SearchService.ts
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: {}
},
]
})
});
}
}

0 comments on commit 59bc8d7

Please sign in to comment.