Skip to content

Commit

Permalink
test(api): Read a product and typecheck SKU string
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jun 15, 2022
1 parent d424760 commit f3a3b98
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/api#readme",
"scripts": {
"build": "zx scripts/build.mjs",
"test": "tsc --noEmit --noImplicitAny"
"test": "zx scripts/test.mjs"
}
}
}
4 changes: 4 additions & 0 deletions packages/api/scripts/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* global $ */

await $`tsc -p ../../tsconfig.test.json`;
await $`tsx tests/index.test.ts`;
21 changes: 21 additions & 0 deletions packages/api/tests/fetch-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable import/no-extraneous-dependencies, no-unused-vars */

import fetch, {
Blob,
blobFrom,
blobFromSync,
File,
fileFrom,
fileFromSync,
FormData,
Headers,
Request,
Response,
} from 'node-fetch';

if (!globalThis.fetch) {
globalThis.fetch = fetch;
globalThis.Headers = Headers;
globalThis.Request = Request;
globalThis.Response = Response;
}
14 changes: 14 additions & 0 deletions packages/api/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable no-console */
import './fetch-polyfill';
import callApi from '../src/index';

callApi({
storeId: 1056,
method: 'get',
endpoint: 'products/618041aa239b7206d3fc06de',
}).then(({ data }) => {
if (data.sku === 'string') {
console.log('\\o/');
}
console.info(`✓ Read product ${data.sku} and checked SKU type string`);
});
13 changes: 0 additions & 13 deletions packages/api/tests/types.test.ts

This file was deleted.

0 comments on commit f3a3b98

Please sign in to comment.