Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ on:
branches: ["main"]

jobs:
build:
static-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: ".node-version"
cache: "npm"
- run: npm ci
- name: Format Check
run: npm run format
- name: Lint
run: npm run lint
- name: Type Check
run: npm run typecheck

build-and-test:
runs-on: ubuntu-latest

strategy:
Expand All @@ -26,5 +43,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build
- run: npm test
- name: Build
run: npm run build
- name: Unit Tests
run: npm run test
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
run: |
npm ci
npm run lint
npm run typecheck
npm run test
npm run build
- run: npm publish
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"scripts": {
"build": "tsup",
"postbuild": "mkdir -p ./dist/umd/ && cp -pR ./dist/iife/* ./dist/umd",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src",
"lint": "eslint ./src ./tests",
"lint:fix": "eslint --fix ./src ./tests",
"format": "prettier --check ./src ./tests",
"format:fix": "prettier --write ./src ./tests",
"typecheck": "tsc --noEmit",
"test": "jest --coverage=false",
"test:coverage": "jest --coverage=true"
},
Expand Down
17 changes: 12 additions & 5 deletions tests/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ describe('get', () => {
test('Return error message in case of server error', () => {
// Create temporary server error
server.use(
http.get(`${testBaseUrl}/list-type`, () => {
return HttpResponse.json({ message: 'Internal Server Error' }, { status: 500 });
}, { once: true })
http.get(
`${testBaseUrl}/list-type`,
() => {
return HttpResponse.json(
{ message: 'Internal Server Error' },
{ status: 500 },
);
},
{ once: true },
),
);

expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
new Error(
'fetch API response status: 500\n message is `Internal Server Error`'
)
'fetch API response status: 500\n message is `Internal Server Error`',
),
);
});
});
176 changes: 124 additions & 52 deletions tests/getAllContentIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,32 @@ describe('getAllContentIds', () => {

test('should fetch all content ids', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

const result = await client.getAllContentIds({
Expand All @@ -40,32 +54,60 @@ describe('getAllContentIds', () => {

test('should handle pagination and fetch more than limit', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 250,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index + 100}` })),
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
.fill(null)
.map((_, index) => ({ id: `id${index + 100}` })),
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(50)
.fill(null)
.map((_, index) => ({ id: `id${index + 200}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ id: `id${index + 200}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

const result = await client.getAllContentIds({
Expand All @@ -79,18 +121,32 @@ describe('getAllContentIds', () => {

test('should fetch all content ids with alternateField field', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ url: `id${index}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ url: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

const result = await client.getAllContentIds({
Expand All @@ -105,18 +161,34 @@ describe('getAllContentIds', () => {

test('should throw error when alternateField field is not string', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map(() => ({ image: { url: 'url', width: 100, height: 100 } })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map(() => ({
image: { url: 'url', width: 100, height: 100 },
})),
},
{ status: 200 },
);
},
{ once: true },
),
);

await expect(
Expand Down
Loading