Skip to content

Commit

Permalink
Update msw library and http mocks
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed Nov 8, 2023
1 parent 516800f commit 4d55125
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 870 deletions.
425 changes: 98 additions & 327 deletions services/tenant-ui/frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/tenant-ui/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"flat": "^6.0.1",
"glob": "^10.3.10",
"jsdom": "^22.1.0",
"msw": "^1.3.2",
"msw": "^2.0.4",
"prettier": "^3.0.3",
"sass": "^1.69.4",
"typescript": "^5.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const makeReservationAutoApprove = {

const makeReservationVerify = {
reservation_id: 'reservation_id',
reservation_pwd: null,
reservation_pwd: '',
};

const checkIn = {
Expand Down
32 changes: 17 additions & 15 deletions services/tenant-ui/frontend/test/__mocks__/api/routes/acapy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';

import { API_PATH } from '@/helpers/constants';
import { acapyResponse } from '../responses';

export const successHandlers = [
rest.all(API_PATH.TEST_TENANT_PROXY, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(acapyResponse.basic));
}),
http.all(API_PATH.TEST_TENANT_PROXY, () =>
HttpResponse.json(acapyResponse.basic)
),
];

export const authErrorHandlers = [
rest.all(API_PATH.TEST_TENANT_PROXY, (req, res, ctx) => {
return res(
ctx.status(401),
ctx.json({
reason: `Test: ${req.headers.get('Authorization')}`,
})
);
}),
http.all(API_PATH.TEST_TENANT_PROXY, ({ request }) =>
HttpResponse.json(
{
reason: `Test: ${request.headers.get('Authorization')}`,
},
{
status: 401,
}
)
),
];

export const unknownErrorHandlers = [
rest.all(API_PATH.TEST_TENANT_PROXY, (req, res, ctx) => {
return res(ctx.status(500), ctx.json({}));
}),
http.all(API_PATH.TEST_TENANT_PROXY, () =>
HttpResponse.json({}, { status: 500 })
),
];
17 changes: 5 additions & 12 deletions services/tenant-ui/frontend/test/__mocks__/api/routes/config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';

import { API_PATH } from '@/helpers/constants';
import { configResponse } from '../responses';
import { fullPathWithProxyTenant } from './utils/utils';

export const successHandlers = [
rest.get(API_PATH.CONFIG, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(configResponse.config));
}),
rest.get(
fullPathWithProxyTenant(API_PATH.SERVER_PLUGINS),
(req, res, ctx) => {
return res(ctx.status(200), ctx.json(configResponse.plugins));
}
http.get(API_PATH.CONFIG, () => HttpResponse.json(configResponse.config)),
http.get(fullPathWithProxyTenant(API_PATH.SERVER_PLUGINS), () =>
HttpResponse.json(configResponse.plugins)
),
];

export const unknownErrorHandlers = [
rest.get(API_PATH.CONFIG, (req, res, ctx) => {
return res(ctx.status(500), ctx.json({}));
}),
http.get(API_PATH.CONFIG, () => HttpResponse.json({}, { status: 500 })),
];
88 changes: 37 additions & 51 deletions services/tenant-ui/frontend/test/__mocks__/api/routes/connection.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,69 @@
import { rest } from 'msw';
import { HttpResponse, http } from 'msw';

import { API_PATH } from '@/helpers/constants';
import { connectionResponse } from '../responses';
import { fullPathWithProxyTenant } from './utils/utils';

export const successHandlers = [
rest.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS), (req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.listConnections))
http.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS), () =>
HttpResponse.json(connectionResponse.listConnections)
),
rest.get(
fullPathWithProxyTenant(API_PATH.CONNECTIONS) + '/:id',
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.getConnection))
http.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS) + '/:id', () =>
HttpResponse.json(connectionResponse.getConnection)
),
rest.get(
http.get(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_INVITATION('test-uuid')),
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.getConnectionInvitation))
() => HttpResponse.json(connectionResponse.getConnectionInvitation)
),
rest.post(
http.post(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_CREATE_INVITATION),
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.createConnection))
() => HttpResponse.json(connectionResponse.createConnection)
),
rest.post(
http.post(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_RECEIVE_INVITATION),
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.receiveInvitation))
() => HttpResponse.json(connectionResponse.receiveInvitation)
),
rest.post(
fullPathWithProxyTenant(API_PATH.DID_EXCHANGE_CREATE_REQUEST),
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.didExchange))
http.post(fullPathWithProxyTenant(API_PATH.DID_EXCHANGE_CREATE_REQUEST), () =>
HttpResponse.json(connectionResponse.didExchange)
),
rest.put(
fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')),
(req, res, ctx) =>
res(ctx.status(200), ctx.json(connectionResponse.getConnection))
http.put(fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')), () =>
HttpResponse.json(connectionResponse.getConnection)
),
rest.delete(
fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')),
(req, res, ctx) => res(ctx.status(200), ctx.json({}))
http.delete(fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')), () =>
HttpResponse.json({})
),
];

export const unknownErrorHandlers = [
rest.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS), (req, res, ctx) => {
return res(ctx.status(500), ctx.json({}));
}),
rest.get(
fullPathWithProxyTenant(API_PATH.CONNECTIONS) + '/:id',
(req, res, ctx) => res(ctx.status(500), ctx.json({}))
),
rest.get(
http.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS), () =>
HttpResponse.json({}, { status: 500 })
),
http.get(fullPathWithProxyTenant(API_PATH.CONNECTIONS) + '/:id', () =>
HttpResponse.json({}, { status: 500 })
),
http.get(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_INVITATION('test-uuid')),
(req, res, ctx) => res(ctx.status(500), ctx.json({}))
() => HttpResponse.json({}, { status: 500 })
),
rest.post(
http.post(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_CREATE_INVITATION),
(req, res, ctx) => {
return res(ctx.status(500), ctx.json({}));
() => {
return HttpResponse.json({}, { status: 500 });
}
),
rest.post(
http.post(
fullPathWithProxyTenant(API_PATH.CONNECTIONS_RECEIVE_INVITATION),
(req, res, ctx) => {
return res(ctx.status(500), ctx.json({}));
() => {
return HttpResponse.json({}, { status: 500 });
}
),
rest.post(
fullPathWithProxyTenant(API_PATH.DID_EXCHANGE_CREATE_REQUEST),
(req, res, ctx) => res(ctx.status(500), ctx.json({}))
http.post(fullPathWithProxyTenant(API_PATH.DID_EXCHANGE_CREATE_REQUEST), () =>
HttpResponse.json({}, { status: 500 })
),
rest.put(
fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')),
(req, res, ctx) => res(ctx.status(500), ctx.json({}))
http.put(fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')), () =>
HttpResponse.json({}, { status: 500 })
),
rest.delete(
fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')),
(req, res, ctx) => res(ctx.status(500), ctx.json({}))
http.delete(fullPathWithProxyTenant(API_PATH.CONNECTION('test-uuid')), () =>
HttpResponse.json({}, { status: 500 })
),
];
Loading

0 comments on commit 4d55125

Please sign in to comment.