Fix MSW and storybook setup (#2976)
* Fix MSW and storybook setup * Fix * Fix * Fixes * Fix * Fix * Fix
This commit is contained in:
@ -1,16 +1,14 @@
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
import { graphql } from 'msw';
|
||||
import { graphql, HttpResponse } from 'msw';
|
||||
|
||||
import { CREATE_EVENT } from '@/analytics/graphql/queries/createEvent';
|
||||
import { GET_CLIENT_CONFIG } from '@/client-config/graphql/queries/getClientConfig';
|
||||
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '@/object-metadata/graphql/queries';
|
||||
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
|
||||
import { mockedActivities } from '~/testing/mock-data/activities';
|
||||
|
||||
import { mockedCompaniesData } from './mock-data/companies';
|
||||
import { mockedObjectMetadataItems } from './mock-data/metadata';
|
||||
import { mockedPeopleData } from './mock-data/people';
|
||||
import { mockedUsersData } from './mock-data/users';
|
||||
import { mockedViewFieldsData } from './mock-data/view-fields';
|
||||
import { mockedViewsData } from './mock-data/views';
|
||||
|
||||
@ -20,53 +18,52 @@ const metadataGraphql = graphql.link(
|
||||
|
||||
export const graphqlMocks = {
|
||||
handlers: [
|
||||
graphql.query(getOperationName(GET_CURRENT_USER) ?? '', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
currentUser: mockedUsersData[0],
|
||||
}),
|
||||
);
|
||||
}),
|
||||
graphql.mutation(getOperationName(CREATE_EVENT) ?? '', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
// graphql.query(getOperationName(GET_CURRENT_USER) ?? '', () => {
|
||||
// return HttpResponse.json({
|
||||
// data: {
|
||||
// currentUser: mockedUsersData[0],
|
||||
// },
|
||||
// });
|
||||
// }),
|
||||
graphql.mutation(getOperationName(CREATE_EVENT) ?? '', () => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
createEvent: { success: 1, __typename: 'Event' },
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
graphql.query(
|
||||
getOperationName(GET_CLIENT_CONFIG) ?? '',
|
||||
(req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
clientConfig: {
|
||||
signInPrefilled: true,
|
||||
dataModelSettingsEnabled: true,
|
||||
developersSettingsEnabled: true,
|
||||
debugMode: false,
|
||||
authProviders: { google: true, password: true, magicLink: false },
|
||||
telemetry: { enabled: false, anonymizationEnabled: true },
|
||||
support: {
|
||||
supportDriver: 'front',
|
||||
supportFrontChatId: null,
|
||||
},
|
||||
graphql.query(getOperationName(GET_CLIENT_CONFIG) ?? '', () => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
clientConfig: {
|
||||
signInPrefilled: true,
|
||||
dataModelSettingsEnabled: true,
|
||||
developersSettingsEnabled: true,
|
||||
debugMode: false,
|
||||
authProviders: { google: true, password: true, magicLink: false },
|
||||
telemetry: { enabled: false, anonymizationEnabled: true },
|
||||
support: {
|
||||
supportDriver: 'front',
|
||||
supportFrontChatId: null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
metadataGraphql.query(
|
||||
getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? '',
|
||||
(req, res, ctx) => {
|
||||
return res(ctx.data({ objects: mockedObjectMetadataItems }));
|
||||
() => {
|
||||
return HttpResponse.json({
|
||||
data: { objects: mockedObjectMetadataItems },
|
||||
});
|
||||
},
|
||||
),
|
||||
graphql.query('FindManyViews', (req, res, ctx) => {
|
||||
const objectMetadataId = req.variables.filter.objectMetadataId.eq;
|
||||
const viewType = req.variables.filter.type.eq;
|
||||
graphql.query('FindManyViews', ({ variables }) => {
|
||||
const objectMetadataId = variables.filter.objectMetadataId.eq;
|
||||
const viewType = variables.filter.type.eq;
|
||||
|
||||
return res(
|
||||
ctx.data({
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
views: {
|
||||
edges: mockedViewsData
|
||||
.filter(
|
||||
@ -85,14 +82,14 @@ export const graphqlMocks = {
|
||||
endCursor: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
graphql.query('FindManyViewFields', (req, res, ctx) => {
|
||||
const viewId = req.variables.filter.view.eq;
|
||||
graphql.query('FindManyViewFields', ({ variables }) => {
|
||||
const viewId = variables.filter.view.eq;
|
||||
|
||||
return res(
|
||||
ctx.data({
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
viewFields: {
|
||||
edges: mockedViewFieldsData
|
||||
.filter((viewField) => viewField.viewId === viewId)
|
||||
@ -107,12 +104,12 @@ export const graphqlMocks = {
|
||||
endCursor: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
graphql.query('FindManyCompanies', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
graphql.query('FindManyCompanies', () => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
companies: {
|
||||
edges: mockedCompaniesData.map((company) => ({
|
||||
node: company,
|
||||
@ -125,12 +122,12 @@ export const graphqlMocks = {
|
||||
endCursor: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
graphql.query('FindManyPeople', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
graphql.query('FindManyPeople', () => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
people: {
|
||||
edges: mockedPeopleData.map((person) => ({
|
||||
node: person,
|
||||
@ -143,12 +140,12 @@ export const graphqlMocks = {
|
||||
endCursor: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
graphql.query('FindManyActivities', (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.data({
|
||||
graphql.query('FindManyActivities', () => {
|
||||
return HttpResponse.json({
|
||||
data: {
|
||||
activities: {
|
||||
edges: mockedActivities.map((activities) => ({
|
||||
node: activities,
|
||||
@ -161,8 +158,8 @@ export const graphqlMocks = {
|
||||
endCursor: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user