-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #796 from danskernesdigitalebibliotek/DDFLSBP-318-…
…tilfoje-konfiguration-af-soge-vs-visningsprofil Expanding fetching system for FBI to handle multiple urls
- Loading branch information
Showing
18 changed files
with
180 additions
and
28 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
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
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
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
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
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
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
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
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
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
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
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
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
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,102 @@ | ||
import { QueryFunctionContext } from "react-query"; | ||
import { beforeAll, vi } from "vitest"; | ||
import { getServiceBaseUrl } from "../utils/reduxMiddleware/extractServiceBaseUrls"; | ||
import queryMap from "./queryMap"; | ||
|
||
type Baseurl = typeof queryMap[keyof typeof queryMap]; | ||
|
||
export const resolveBaseUrl = (query?: string) => { | ||
if (!query) { | ||
return getServiceBaseUrl(queryMap.default) as Baseurl; | ||
} | ||
|
||
return getServiceBaseUrl( | ||
queryMap[query as keyof typeof queryMap] || queryMap.default | ||
) as Baseurl; | ||
}; | ||
|
||
export const getQueryUrlFromContext = ( | ||
context: QueryFunctionContext | undefined | ||
) => { | ||
// Get the default base url if no context. | ||
if (!context) { | ||
return resolveBaseUrl(); | ||
} | ||
|
||
const { queryKey } = context; | ||
const [queryName] = queryKey; | ||
return resolveBaseUrl(queryName as string); | ||
}; | ||
|
||
export default {}; | ||
|
||
/* ********************************* Vitest Section ********************************* */ | ||
if (import.meta.vitest) { | ||
const { describe, expect, it } = import.meta.vitest; | ||
|
||
describe("DBC Gateway Requests", () => { | ||
beforeAll(() => { | ||
vi.mock("../utils/reduxMiddleware/extractServiceBaseUrls", async () => { | ||
const urls = { | ||
fbiBaseUrl: "i-am-fbi-url", | ||
fbiSearchBaseUrl: "i-am-fbi-search-url", | ||
fbiMaterialBaseUrl: "i-am-fbi-material-url" | ||
} as const; | ||
|
||
const actual = await vi.importActual( | ||
"../utils/reduxMiddleware/extractServiceBaseUrls" | ||
); | ||
|
||
return { | ||
...(typeof actual === "object" ? actual : {}), | ||
getServiceBaseUrl: (apiBaseUrlKey: keyof typeof urls) => { | ||
return urls[apiBaseUrlKey] ?? urls.fbiBaseUrl; | ||
} | ||
}; | ||
}); | ||
}); | ||
|
||
it("should resolve baseurl based on query name", () => { | ||
expect(resolveBaseUrl("complexSearchWithPagination")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("complexSearchWithPaginationWorkAccess")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("intelligentFacets")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("recommendFromFaust")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("searchFacet")).toEqual("i-am-fbi-search-url"); | ||
expect(resolveBaseUrl("searchWithPagination")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("suggestionsFromQueryString")).toEqual( | ||
"i-am-fbi-search-url" | ||
); | ||
expect(resolveBaseUrl("getInfomedia")).toEqual("i-am-fbi-material-url"); | ||
expect( | ||
resolveBaseUrl("getManifestationViaBestRepresentationByFaust") | ||
).toEqual("i-am-fbi-material-url"); | ||
expect(resolveBaseUrl("getManifestationViaMaterialByFaust")).toEqual( | ||
"i-am-fbi-material-url" | ||
); | ||
expect(resolveBaseUrl("getMaterial")).toEqual("i-am-fbi-material-url"); | ||
expect(resolveBaseUrl("getReviewManifestations")).toEqual( | ||
"i-am-fbi-material-url" | ||
); | ||
expect(resolveBaseUrl("getSmallWork")).toEqual("i-am-fbi-material-url"); | ||
expect(resolveBaseUrl("openOrder")).toEqual("i-am-fbi-material-url"); | ||
}); | ||
|
||
it("should resolve default to the fbi base url if the query is unknown", () => { | ||
expect(resolveBaseUrl("someUnknownQuery")).toEqual("i-am-fbi-url"); | ||
}); | ||
|
||
it("should resolve default to the fbi base url if no query has been specified", () => { | ||
expect(resolveBaseUrl()).toEqual("i-am-fbi-url"); | ||
}); | ||
}); | ||
} |
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 { serviceUrlKeys } from "../utils/reduxMiddleware/extractServiceBaseUrls"; | ||
|
||
// This map is for mapping query names to FBI service base urls. | ||
export default { | ||
// Search requests. | ||
complexSearchWithPagination: serviceUrlKeys.fbiSearch, | ||
complexSearchWithPaginationWorkAccess: serviceUrlKeys.fbiSearch, | ||
intelligentFacets: serviceUrlKeys.fbiSearch, | ||
recommendFromFaust: serviceUrlKeys.fbiSearch, | ||
searchFacet: serviceUrlKeys.fbiSearch, | ||
searchWithPagination: serviceUrlKeys.fbiSearch, | ||
suggestionsFromQueryString: serviceUrlKeys.fbiSearch, | ||
// Material requests. | ||
getInfomedia: serviceUrlKeys.fbiMaterial, | ||
getManifestationViaBestRepresentationByFaust: serviceUrlKeys.fbiMaterial, | ||
getManifestationViaMaterialByFaust: serviceUrlKeys.fbiMaterial, | ||
getMaterial: serviceUrlKeys.fbiMaterial, | ||
getReviewManifestations: serviceUrlKeys.fbiMaterial, | ||
getSmallWork: serviceUrlKeys.fbiMaterial, | ||
openOrder: serviceUrlKeys.fbiMaterial, | ||
// All other requests. | ||
default: serviceUrlKeys.fbi | ||
} as const; |
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
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
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