chore: add fetch funtcion & add tests to helper module

This commit is contained in:
Bart Stefanski 2023-04-16 20:47:49 +02:00
parent e289aeea27
commit 7b5e820285
22 changed files with 315 additions and 17 deletions

1
packages/helper/dist/fetch.d.ts vendored Normal file
View file

@ -0,0 +1 @@
export default function fetch(url: string, options?: RequestInit): Promise<Response>;

8
packages/helper/dist/fetch.js vendored Normal file
View file

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isomorphic_unfetch_1 = require("isomorphic-unfetch");
function fetch(url, options = {}) {
return (0, isomorphic_unfetch_1.default)(url, Object.assign({}, options));
}
exports.default = fetch;
//# sourceMappingURL=fetch.js.map

1
packages/helper/dist/fetch.js.map vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../fetch.ts"],"names":[],"mappings":";;AAAA,2DAAuC;AAEvC,SAAwB,KAAK,CAAC,GAAW,EAAE,UAAuB,EAAE;IAClE,OAAO,IAAA,4BAAM,EAAC,GAAG,oBAAO,OAAO,EAAG,CAAA;AACpC,CAAC;AAFD,wBAEC"}

1
packages/helper/dist/fetch.test.d.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

33
packages/helper/dist/fetch.test.js vendored Normal file
View file

@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fetch_1 = require("./fetch");
const isomorphic_unfetch_1 = require("isomorphic-unfetch");
jest.mock("isomorphic-unfetch", () => jest.fn(() => Promise.resolve(isomorphic_unfetch_1.default)));
describe("fetch", () => {
const url = "https://example.com";
afterEach(() => {
jest.clearAllMocks();
});
it("should make a GET request with default options", async () => {
const response = await (0, fetch_1.default)(url);
expect(response.ok).toBe(true);
expect(response.status).toBe(200);
expect(response.statusText).toBe("OK");
expect(isomorphic_unfetch_1.default).toHaveBeenCalledWith(url, {});
});
it("should make a POST request with options", async () => {
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ data: "test" }),
};
const response = await (0, fetch_1.default)(url, options);
expect(response.ok).toBe(true);
expect(response.status).toBe(200);
expect(response.statusText).toBe("OK");
expect(isomorphic_unfetch_1.default).toHaveBeenCalledWith(url, Object.assign(Object.assign({}, options), { body: JSON.stringify({ data: "test" }) }));
});
});
//# sourceMappingURL=fetch.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"fetch.test.js","sourceRoot":"","sources":["../fetch.test.ts"],"names":[],"mappings":";;AAAA,mCAA2B;AAC3B,2DAAkD;AAElD,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,4BAAiB,CAAC,CAAC,CAAC,CAAA;AAExF,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,MAAM,GAAG,GAAG,qBAAqB,CAAA;IAEjC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,QAAQ,GAAa,MAAM,IAAA,eAAK,EAAC,GAAG,CAAC,CAAA;QAC3C,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAGtC,MAAM,CAAC,4BAAiB,CAAC,CAAC,oBAAoB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SACvC,CAAA;QAED,MAAM,QAAQ,GAAa,MAAM,IAAA,eAAK,EAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACpD,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAGtC,MAAM,CAAC,4BAAiB,CAAC,CAAC,oBAAoB,CAAC,GAAG,kCAC7C,OAAO,KACV,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,IACtC,CAAA;IACJ,CAAC,CAAC,CAAA;AAGJ,CAAC,CAAC,CAAA"}

1
packages/helper/dist/index.d.ts vendored Normal file
View file

@ -0,0 +1 @@
export * from "./fetch";

18
packages/helper/dist/index.js vendored Normal file
View file

@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./fetch"), exports);
//# sourceMappingURL=index.js.map

1
packages/helper/dist/index.js.map vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}

File diff suppressed because one or more lines are too long