v3.14.0 (#4492)
* v3.14.0 * fix: simplify config fetch interceptor implementation * add `loadRemoteConfig` flag to requests * v3.14.0
This commit is contained in:
@@ -5,80 +5,23 @@ import { downloadConfig } from "corePlugins/configs/spec-actions"
|
||||
describe("configs plugin - actions", () => {
|
||||
|
||||
describe("downloadConfig", () => {
|
||||
it("should call the system fetch helper with a provided url", () => {
|
||||
it("should call the system fetch helper with a provided request", () => {
|
||||
const fetchSpy = createSpy(async () => {}).andCallThrough()
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: fetchSpy
|
||||
},
|
||||
getConfigs() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
const url = "http://swagger.io/one"
|
||||
|
||||
downloadConfig(url)(system)
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalledWith({
|
||||
url: url
|
||||
})
|
||||
})
|
||||
it("should allow the globally configured requestInterceptor to modify the request", () => {
|
||||
const fetchSpy = createSpy(async () => {}).andCallThrough()
|
||||
const requestInterceptorSpy = createSpy((req) => {
|
||||
req.url = "http://swagger.io/two"
|
||||
return req
|
||||
}).andCallThrough()
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: fetchSpy
|
||||
},
|
||||
getConfigs() {
|
||||
return {
|
||||
requestInterceptor: requestInterceptorSpy
|
||||
}
|
||||
}
|
||||
const req = {
|
||||
url: "http://swagger.io/one",
|
||||
requestInterceptor: a => a,
|
||||
responseInterceptor: a => a,
|
||||
}
|
||||
|
||||
const url = "http://swagger.io/one"
|
||||
downloadConfig(req)(system)
|
||||
|
||||
downloadConfig(url)(system)
|
||||
|
||||
expect(fetchSpy).toHaveBeenCalledWith({
|
||||
url: "http://swagger.io/two"
|
||||
})
|
||||
})
|
||||
it("should allow the globally configured responseInterceptor to modify the response", async () => {
|
||||
const fetchSpy = createSpy(async (req) => {
|
||||
return {
|
||||
url: req.url,
|
||||
ok: true
|
||||
}
|
||||
}).andCallThrough()
|
||||
const responseInterceptorSpy = createSpy((res) => {
|
||||
res.url = "http://swagger.io/two"
|
||||
return res
|
||||
}).andCallThrough()
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: fetchSpy
|
||||
},
|
||||
getConfigs() {
|
||||
return {
|
||||
responseInterceptor: responseInterceptorSpy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const url = "http://swagger.io/one"
|
||||
|
||||
const res = await downloadConfig(url)(system)
|
||||
|
||||
expect(res).toEqual({
|
||||
url: "http://swagger.io/two",
|
||||
ok: true
|
||||
})
|
||||
expect(fetchSpy).toHaveBeenCalledWith(req)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user