Skip to content

Commit

Permalink
chore(deps-dev): bump msw from 1.3.2 to 2.1.5 (#260)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump msw from 1.3.2 to 2.1.5

Bumps [msw](https://github.com/mswjs/msw) from 1.3.2 to 2.1.5.
- [Release notes](https://github.com/mswjs/msw/releases)
- [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md)
- [Commits](mswjs/msw@v1.3.2...v2.1.5)

---
updated-dependencies:
- dependency-name: msw
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* migrate using codemod

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lion Ralfs <lion.ralfs@gmail.com>
  • Loading branch information
dependabot[bot] and lionralfs authored Feb 3, 2024
1 parent cf15eb4 commit 4cc9f34
Show file tree
Hide file tree
Showing 12 changed files with 648 additions and 950 deletions.
763 changes: 204 additions & 559 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"eslint": "^8.26.0",
"husky": "^9.0.7",
"lint-staged": "^15.2.0",
"msw": "^1.3.2",
"msw": "^2.1.5",
"np": "^9.2.0",
"prettier": "^3.0.0",
"typescript": "^5.2.2",
Expand Down
156 changes: 74 additions & 82 deletions test/integration/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { DiscogsClient } from '@lib/client.js';
import { setupMockAPI } from './setup.js';
import { expect, test, describe } from 'vitest';
Expand All @@ -8,8 +8,8 @@ const server = setupMockAPI();
describe('DiscogsClient', () => {
test('get()', async () => {
server.use(
rest.get('https://api.discogs.com/labels/1', (req, res, ctx) => {
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com/labels/1', () => {
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient();
Expand All @@ -19,8 +19,8 @@ describe('DiscogsClient', () => {

test('Custom configuration', async () => {
server.use(
rest.get('https://www.example.com/labels/1', (req, res, ctx) => {
return res(ctx.status(200), ctx.json({}));
http.get('https://www.example.com/labels/1', () => {
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient().setConfig({ host: 'www.example.com' });
Expand All @@ -30,9 +30,9 @@ describe('DiscogsClient', () => {

test('Media Types (none, default)', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
expect(req.headers.get('Accept')).toBe('application/vnd.discogs.v2.discogs+json');
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com', ({ request }) => {
expect(request.headers.get('Accept')).toBe('application/vnd.discogs.v2.discogs+json');
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient();
Expand All @@ -41,9 +41,9 @@ describe('DiscogsClient', () => {

test('Media Types (html)', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
expect(req.headers.get('Accept')).toBe('application/vnd.discogs.v2.html+json');
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com', ({ request }) => {
expect(request.headers.get('Accept')).toBe('application/vnd.discogs.v2.html+json');
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient().setConfig({ outputFormat: 'html' });
Expand All @@ -52,9 +52,9 @@ describe('DiscogsClient', () => {

test('Media Types (plaintext)', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
expect(req.headers.get('Accept')).toBe('application/vnd.discogs.v2.plaintext+json');
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com', ({ request }) => {
expect(request.headers.get('Accept')).toBe('application/vnd.discogs.v2.plaintext+json');
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient().setConfig({ outputFormat: 'plaintext' });
Expand All @@ -63,11 +63,11 @@ describe('DiscogsClient', () => {

test('User Agent (default)', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
expect(req.headers.get('User-Agent')).toMatch(
http.get('https://api.discogs.com', ({ request }) => {
expect(request.headers.get('User-Agent')).toMatch(
/^@lionralfs\/discogs-client\/dev \+https:\/\/github\.com\/(.+)$/
);
return res(ctx.status(200), ctx.json({}));
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient();
Expand All @@ -76,9 +76,9 @@ describe('DiscogsClient', () => {

test('User Agent (custom)', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
expect(req.headers.get('User-Agent')).toBe('MyDiscogsClient/1.0 +https://example.org');
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com', ({ request }) => {
expect(request.headers.get('User-Agent')).toBe('MyDiscogsClient/1.0 +https://example.org');
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient({ userAgent: 'MyDiscogsClient/1.0 +https://example.org' });
Expand All @@ -87,9 +87,9 @@ describe('DiscogsClient', () => {

test('Auth (userToken)', async () => {
server.use(
rest.get('https://api.discogs.com/oauth/identity', (req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Discogs token=testtoken12345');
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com/oauth/identity', ({ request }) => {
expect(request.headers.get('Authorization')).toBe('Discogs token=testtoken12345');
return HttpResponse.json({}, { status: 200 });
})
);
const client = new DiscogsClient({ auth: { userToken: 'testtoken12345' } });
Expand All @@ -98,9 +98,9 @@ describe('DiscogsClient', () => {

test('Sends OAuth header', async () => {
server.use(
rest.get('https://api.discogs.com/oauth/identity', (req, res, ctx) => {
expect(req.headers.get('Authorization')?.startsWith('OAuth '));
return res(ctx.status(200), ctx.json({}));
http.get('https://api.discogs.com/oauth/identity', ({ request }) => {
expect(request.headers.get('Authorization')?.startsWith('OAuth '));
return HttpResponse.json({}, { status: 200 });
})
);

Expand All @@ -119,16 +119,18 @@ describe('DiscogsClient', () => {

test('Retrieves and passes rate limit info to caller', async () => {
server.use(
rest.get('https://api.discogs.com/oauth/identity', (req, res, ctx) => {
expect(req.headers.get('Authorization')?.startsWith('OAuth '));
return res(
ctx.status(200),
ctx.json({}),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '23',
'X-Discogs-Ratelimit-Remaining': '37',
})
http.get('https://api.discogs.com/oauth/identity', ({ request }) => {
expect(request.headers.get('Authorization')?.startsWith('OAuth '));
return HttpResponse.json(
{},
{
status: 200,
headers: {
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '23',
'X-Discogs-Ratelimit-Remaining': '37',
},
}
);
})
);
Expand All @@ -150,26 +152,30 @@ describe('DiscogsClient', () => {
test('Retries when rate limited', async () => {
let n = 0;
server.use(
rest.get('https://api.discogs.com/oauth/identity', (req, res, ctx) => {
http.get('https://api.discogs.com/oauth/identity', () => {
if (n++ == 0) {
return res(
ctx.status(429),
ctx.json({ message: "you're rate limited" }),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '60',
'X-Discogs-Ratelimit-Remaining': '0',
})
return HttpResponse.json(
{ message: "you're rate limited" },
{
status: 429,
headers: {
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '60',
'X-Discogs-Ratelimit-Remaining': '0',
},
}
);
} else {
return res(
ctx.status(200),
ctx.json({ message: "you're good" }),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '59',
'X-Discogs-Ratelimit-Remaining': '1',
})
return HttpResponse.json(
{ message: "you're good" },
{
status: 200,
headers: {
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '59',
'X-Discogs-Ratelimit-Remaining': '1',
},
}
);
}
})
Expand All @@ -195,27 +201,11 @@ describe('DiscogsClient', () => {
test('Throws when retrying but end of retries is reached', async () => {
let n = 0;
server.use(
rest.get('https://api.discogs.com/oauth/identity', (req, res, ctx) => {
http.get('https://api.discogs.com/oauth/identity', () => {
if (n++ == 0) {
return res(
ctx.status(429),
ctx.json({ message: "you're rate limited 1" }),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '60',
'X-Discogs-Ratelimit-Remaining': '0',
})
);
return HttpResponse.json({ message: "you're rate limited 1" }, { status: 429 });
} else {
return res(
ctx.status(429),
ctx.json({ message: "you're rate limited 2" }),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '60',
'X-Discogs-Ratelimit-Remaining': '0',
})
);
return HttpResponse.json({ message: "you're rate limited 2" }, { status: 429 });
}
})
);
Expand All @@ -232,20 +222,22 @@ describe('DiscogsClient', () => {

test('Should return client and server info in about call', async () => {
server.use(
rest.get('https://api.discogs.com', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
http.get('https://api.discogs.com', () => {
return HttpResponse.json(
{
hello: 'Welcome to the Discogs API.',
api_version: 'v2',
documentation_url: 'http://www.discogs.com/developers/',
statistics: { releases: 16327979, artists: 8602060, labels: 1991222 },
}),
ctx.set({
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '59',
'X-Discogs-Ratelimit-Remaining': '1',
})
},
{
status: 200,
headers: {
'X-Discogs-Ratelimit': '60',
'X-Discogs-Ratelimit-Used': '59',
'X-Discogs-Ratelimit-Remaining': '1',
},
}
);
})
);
Expand Down
Loading

0 comments on commit 4cc9f34

Please sign in to comment.