Add JSON field type and Event object (#4566)
* Add JSON field type and Event object * Simplify code * Adress PR comments and add featureFlag
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const CREATE_EVENT = gql`
|
||||
mutation CreateEvent($type: String!, $data: JSON!) {
|
||||
createEvent(type: $type, data: $data) {
|
||||
success
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -0,0 +1,9 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const TRACK = gql`
|
||||
mutation Track($type: String!, $data: JSON!) {
|
||||
track(type: $type, data: $data) {
|
||||
success
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -11,8 +11,8 @@ const mocks: MockedResponse[] = [
|
||||
{
|
||||
request: {
|
||||
query: gql`
|
||||
mutation CreateEvent($type: String!, $data: JSON!) {
|
||||
createEvent(type: $type, data: $data) {
|
||||
mutation Track($type: String!, $data: JSON!) {
|
||||
track(type: $type, data: $data) {
|
||||
success
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ const mocks: MockedResponse[] = [
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: {
|
||||
createEvent: {
|
||||
track: {
|
||||
success: true,
|
||||
},
|
||||
},
|
||||
|
||||
@ -4,10 +4,10 @@ import { RecoilRoot } from 'recoil';
|
||||
|
||||
import { useTrackEvent } from '../useTrackEvent';
|
||||
|
||||
const mockCreateEventMutation = jest.fn();
|
||||
const mockTrackMutation = jest.fn();
|
||||
|
||||
jest.mock('~/generated/graphql', () => ({
|
||||
useCreateEventMutation: () => [mockCreateEventMutation],
|
||||
useTrackMutation: () => [mockTrackMutation],
|
||||
}));
|
||||
|
||||
describe('useTrackEvent', () => {
|
||||
@ -17,8 +17,8 @@ describe('useTrackEvent', () => {
|
||||
renderHook(() => useTrackEvent(eventType, eventData), {
|
||||
wrapper: RecoilRoot,
|
||||
});
|
||||
expect(mockCreateEventMutation).toHaveBeenCalledTimes(1);
|
||||
expect(mockCreateEventMutation).toHaveBeenCalledWith({
|
||||
expect(mockTrackMutation).toHaveBeenCalledTimes(1);
|
||||
expect(mockTrackMutation).toHaveBeenCalledWith({
|
||||
variables: { type: eventType, data: eventData },
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@ import { useCallback } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { telemetryState } from '@/client-config/states/telemetryState';
|
||||
import { useCreateEventMutation } from '~/generated/graphql';
|
||||
import { useTrackMutation } from '~/generated/graphql';
|
||||
|
||||
interface EventLocation {
|
||||
pathname: string;
|
||||
@ -14,7 +14,7 @@ export interface EventData {
|
||||
|
||||
export const useEventTracker = () => {
|
||||
const telemetry = useRecoilValue(telemetryState());
|
||||
const [createEventMutation] = useCreateEventMutation();
|
||||
const [createEventMutation] = useTrackMutation();
|
||||
|
||||
return useCallback(
|
||||
(eventType: string, eventData: EventData) => {
|
||||
|
||||
@ -77,8 +77,8 @@ describe('useApolloFactory', () => {
|
||||
await act(async () => {
|
||||
await result.current.factory.mutate({
|
||||
mutation: gql`
|
||||
mutation CreateEvent($type: String!, $data: JSON!) {
|
||||
createEvent(type: $type, data: $data) {
|
||||
mutation Track($type: String!, $data: JSON!) {
|
||||
track(type: $type, data: $data) {
|
||||
success
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ const makeRequest = async () => {
|
||||
|
||||
await client.mutate({
|
||||
mutation: gql`
|
||||
mutation CreateEvent($type: String!, $data: JSON!) {
|
||||
createEvent(type: $type, data: $data) {
|
||||
mutation Track($type: String!, $data: JSON!) {
|
||||
track(type: $type, data: $data) {
|
||||
success
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export type FeatureFlagKey =
|
||||
| 'IS_BLOCKLIST_ENABLED'
|
||||
| 'IS_CALENDAR_ENABLED'
|
||||
| 'IS_QUICK_ACTIONS_ENABLED';
|
||||
| 'IS_QUICK_ACTIONS_ENABLED'
|
||||
| 'IS_EVENT_OBJECT_ENABLED';
|
||||
|
||||
Reference in New Issue
Block a user