Skip to content

Commit

Permalink
chore(deps): update mock service worker (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathannorris authored Oct 26, 2023
1 parent 18f8146 commit 3ee5528
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 235 deletions.
1 change: 1 addition & 0 deletions lib/shared/server-request/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export async function post(
Authorization: sdkKey,
'Content-Type': 'application/json',
}

const res = await _fetch(url, {
...config,
headers: postHeaders,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"bootstrap": "5.1.3",
"class-transformer": "0.5.1",
"core-js": "^3.6.5",
"cross-fetch": "^3.1.5",
"cross-fetch": "^3.1.8",
"eslint-plugin-lodash": "^7.4.0",
"fetch-retry": "^5.0.3",
"hoist-non-react-statics": "^3.3.2",
Expand Down Expand Up @@ -153,7 +153,7 @@
"metro-react-native-babel-preset": "0.74.1",
"metro-react-native-babel-transformer": "0.74.1",
"metro-resolver": "0.74.1",
"msw": "^0.47.3",
"msw": "^2.0.0",
"npm-run-all": "^4.1.5",
"nx": "16.5.5",
"prettier": "^2.8.8",
Expand Down
10 changes: 4 additions & 6 deletions sdk/js-cloud-server/__tests__/cloudClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ const respond500User = { user_id: '500' }

jest.mock('fetch-retry')

beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('DevCycleCloudClient without EdgeDB', () => {
beforeAll(async () => {
client = DVC.initializeDevCycle('dvc_server_token', {
logLevel: 'error',
})
server.listen()
})
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('variable', () => {
it('to return a Value and not be defaulted', async () => {
Expand Down Expand Up @@ -247,10 +248,7 @@ describe('DevCycleCloudClient with EdgeDB Enabled', () => {
logLevel: 'error',
enableEdgeDB: true,
})
server.listen()
})
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('variable', () => {
it('to return a Value and not be defaulted', async () => {
Expand Down
2 changes: 1 addition & 1 deletion sdk/js-cloud-server/__tests__/initialize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DevCycleCloudClient, initializeDevCycle } from '../src/index'
import { initializeDevCycle } from '../src/index'

describe('JS Cloud Bucketing Server SDK Initialize', () => {
afterAll(() => {
Expand Down
112 changes: 60 additions & 52 deletions sdk/js-cloud-server/src/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,110 @@
// src/mocks/handlers.js
import { rest } from 'msw'
import { http, HttpResponse } from 'msw'

export const handlers = [
rest.post(
http.post(
'https://bucketing-api.devcycle.com/v1/variables/test-key-not-in-config',
(req, res, ctx) => {
return res(ctx.status(404), ctx.json({}))
() => {
console.log
return HttpResponse.json({}, { status: 404 })
},
),
rest.post(
http.post(
'https://bucketing-api.devcycle.com/v1/variables/test-key',
(req, res, ctx) => {
const enableEdgeDB = req.url.searchParams.get('enableEdgeDB')
const { user_id } = req.body as Record<string, any>
async ({ request }) => {
const body = await request.json()
const { user_id } = body as Record<string, any>
const url = new URL(request.url)
const enableEdgeDB = url.searchParams.get('enableEdgeDB')

if (user_id === '500') {
return res(ctx.status(500))
return HttpResponse.json({}, { status: 500 })
}

if (enableEdgeDB) {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
key: 'test-key-edgedb',
value: true,
type: 'Boolean',
defaultValue: false,
}),
},
{ status: 200 },
)
} else {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
key: 'test-key',
value: true,
type: 'Boolean',
defaultValue: false,
}),
},
{ status: 200 },
)
}
},
),
rest.post(
http.post(
'https://bucketing-api.devcycle.com/v1/variables',
(req, res, ctx) => {
const { user_id } = req.body as Record<string, any>
const enableEdgeDB = req.url.searchParams.get('enableEdgeDB')
async ({ request }) => {
const body = await request.json()
const { user_id } = body as Record<string, any>
const url = new URL(request.url)
const enableEdgeDB = url.searchParams.get('enableEdgeDB')

if (user_id === 'bad') {
return res(ctx.status(400))
return HttpResponse.json({}, { status: 400 })
} else if (user_id === '500') {
return res(ctx.status(500))
return HttpResponse.json({}, { status: 500 })
} else if (user_id === 'empty') {
return res(ctx.status(200), ctx.json({}))
return HttpResponse.json({}, { status: 200 })
} else {
if (enableEdgeDB) {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
'test-key-edgedb': {
key: 'test-key-edgedb',
value: true,
type: 'Boolean',
defaultValue: false,
},
}),
},
{ status: 200 },
)
} else {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
'test-key': {
key: 'test-key',
value: true,
type: 'Boolean',
defaultValue: false,
},
}),
},
{ status: 200 },
)
}
}
},
),
rest.post(
http.post(
'https://bucketing-api.devcycle.com/v1/features',
(req, res, ctx) => {
const { user_id } = req.body as Record<string, any>
const enableEdgeDB = req.url.searchParams.get('enableEdgeDB')
async ({ request }) => {
const body = await request.json()
const { user_id } = body as Record<string, any>
const url = new URL(request.url)
const enableEdgeDB = url.searchParams.get('enableEdgeDB')

if (user_id === 'bad') {
return res(ctx.status(400))
return HttpResponse.json({}, { status: 400 })
} else if (user_id === '500') {
return res(ctx.status(500))
return HttpResponse.json({}, { status: 500 })
} else if (user_id === 'empty') {
return res(ctx.status(200), ctx.json({}))
return HttpResponse.json({}, { status: 200 })
} else {
if (enableEdgeDB) {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
'test-feature-edgedb': {
_id: 'test-id',
_variation: 'variation-id',
Expand All @@ -107,12 +113,12 @@ export const handlers = [
key: 'test-feature-edgedb',
type: 'release',
},
}),
},
{ status: 200 },
)
} else {
return res(
ctx.status(200),
ctx.json({
return HttpResponse.json(
{
'test-feature': {
_id: 'test-id',
_variation: 'variation-id',
Expand All @@ -121,21 +127,23 @@ export const handlers = [
key: 'test-feature',
type: 'release',
},
}),
},
{ status: 200 },
)
}
}
},
),
rest.post(
http.post(
'https://bucketing-api.devcycle.com/v1/track',
(req, res, ctx) => {
const { user } = req.body as Record<string, any>
async ({ request }) => {
const body = await request.json()
const { user } = body as Record<string, any>

if (user.user_id === 'bad') {
return res(ctx.status(400))
return HttpResponse.json({}, { status: 400 })
} else {
return res(ctx.status(201))
return HttpResponse.json({}, { status: 201 })
}
},
),
Expand Down
Loading

2 comments on commit 3ee5528

@vercel
Copy link

@vercel vercel bot commented on 3ee5528 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 3ee5528 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.