Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async fetch(url: string, init?: RequestInit): Promise {
const seed = FixtureStorage.createByFetchParams>(url, init)
const seedFixture = seed.get()
if (seedFixture && !seed.expired) {
// seed exists => return seed
return createResponse(seedFixture)
}
const res = await fetch(url, init)
let fixture: Fixture = {
body: (await res.json()) || (await res.text()),
options: {
headers: res.headers,
status: res.status,
statusText: res.statusText,
},
async fetch(url: string, init?: RequestInit): Promise {
const seed = FixtureStorage.createByUrl>(
url,
init,
this.testScope
)
try {
const seedFixture = seed.get()
if (!seed.expired) {
// seed exists => return seed
return createResponse(seedFixture)
}
} catch {
// ignore
}
const fixture = await this.fetchFixture(url, init)
seed.set(fixture)
async fetch(url: string, init?: RequestInit): Promise {
const seed = FixtureStorage.createByFetchParams>(url, init)
const fixture = seed.get()
return createResponse(fixture)
}
}
async fetch(url: string, init?: RequestInit): Promise {
const seed = FixtureStorage.createByFetchParams>(url, init)
const fixture = seed.get()
if (!fixture) {
throw new Error('Http: fixture (seed) is missing.')
}
if (seed.expired) {
throw new Error('Http: fixture (seed) is expired.')
}
return createResponse(fixture)
}
}
const seedify = async (fnc: ClientFunction, name: string, args: any) => {
const seed = FxSt.createByUrl(
`${endpoint}/${name}`,
args,
this.testScope
)
try {
try {
if (seed.expired) {
throw new Error()
}
const response = seed.get()
handleSeedError(response)
return response
} catch {
const response = await fnc(args)
seed.set(response)
return response
const purify = async (fnc: ClientFunction, name: string, args: any) => {
const seed = FixtureStorage.createByUrl(
`${endpoint}/${name}`,
args,
this.testScope
)
const response = seed.get()
handleSeedError(response)
return response
}
async getClient(opts: ClientOptions): Promise {
try {
const wsdl = await this.fetchWsdl(opts)
const endpoint = getEndpoint(opts)
if (!wsdlIsFile(opts)) {
const seed = FxSt.createByWsdlUrl(endpoint)
try {
seed.get()
if (seed.expired) {
throw new Error()
}
} catch {
seed.set(wsdl)
}
}
const client = await getClientInternal(opts)
const seedClient = await this.seedifyClient(client, endpoint)
return seedClient
} catch (e) {
throw new SoapError(
`Unable to create the SOAP seed mode client: ${e.message}`,
e
async getClient(opts: ClientOptions): Promise {
const endpoint = getEndpoint(opts)
const wsdlPath = `seed/${endpoint}.wsdl`.replace('://', '/')
const options = { endpoint, wsdlPath, credentials: opts.credentials }
try {
const client = await getClientInternal(options)
const pureClient = await this.purifyClient(client, endpoint)
return pureClient
} catch (e) {
if (e.code === 'ENOENT') {
throw new SeedError(`Fixture (seed) WSDL is missing: ${wsdlPath}`, e)
}
throw new SoapError(`Unable to create pure mode client: ${e.message}`, e)
}
}