[TEST] Covering useDeleteOne relations optimistic cache behavior (#10238)
## Introduction Added coverage on the `useDeleteOneRecord` hooks, especially its optimistic behavior feature. Introduced a new testing tool `InMemoryTestingCacheInstance` that has builtin very basic expectors in order to avoid future duplication when covering others record hooks `update, create, destroy` etc etc ## Notes Added few comments in this PR regarding some builtin functions I've created around companies and people mocked object model and that I think could be cool to spread and centralize within a dedicated "class template" Also put in light that unless I'm mistaken some tests are running on `RecordNode` and not `RecordObject` Took few directions on my own that as I always I would suggestion nor remarks on them ! Let me know ## Misc - Should we refactor `useDeleteOneRecord` tests to follow `eachTesting` pattern ? => I feel like this is inappropriate as this hooks is already high level, the only plus value would be less tests code despite readability IMO
This commit is contained in:
@ -4,9 +4,9 @@ import { computeDepthOneRecordGqlFieldsFromRecord } from '@/object-record/graphq
|
||||
import { FieldActorForInputValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { computeOptimisticRecordFromInput } from '@/object-record/utils/computeOptimisticRecordFromInput';
|
||||
import { InMemoryCache } from '@apollo/client';
|
||||
import { getCompanyObjectMetadataItem } from '~/testing/mock-data/companies';
|
||||
import { getMockCompanyObjectMetadataItem } from '~/testing/mock-data/companies';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
|
||||
import { getPersonObjectMetadataItem } from '~/testing/mock-data/people';
|
||||
import { getMockPersonObjectMetadataItem } from '~/testing/mock-data/people';
|
||||
import { mockCurrentWorkspaceMembers } from '~/testing/mock-data/workspace-members';
|
||||
|
||||
describe('computeOptimisticRecordFromInput', () => {
|
||||
@ -14,7 +14,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
const currentWorkspaceMemberFullname = `${currentWorkspaceMember.name.firstName} ${currentWorkspaceMember.name.lastName}`;
|
||||
it('should generate correct optimistic record if no relation field is present', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
const result = computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
@ -33,7 +33,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record with actor field', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
const actorFieldValueForInput: FieldActorForInputValue = {
|
||||
context: {},
|
||||
source: 'API',
|
||||
@ -62,7 +62,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record createdBy when recordInput contains id', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
const result = computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
objectMetadataItems: generatedMockObjectMetadataItems,
|
||||
@ -90,7 +90,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record if relation field is present but cache is empty', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
const result = computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
@ -109,8 +109,8 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record even if recordInput contains field __typename', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const companyObjectMetadataItem = getCompanyObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
const companyObjectMetadataItem = getMockCompanyObjectMetadataItem();
|
||||
|
||||
const companyRecord = {
|
||||
id: '123',
|
||||
@ -154,8 +154,8 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record if relation field is present and cache is not empty', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const companyObjectMetadataItem = getCompanyObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
const companyObjectMetadataItem = getMockCompanyObjectMetadataItem();
|
||||
|
||||
const companyRecord = {
|
||||
id: '123',
|
||||
@ -198,7 +198,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should generate correct optimistic record if relation field is null and cache is empty', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
const result = computeOptimisticRecordFromInput({
|
||||
currentWorkspaceMember,
|
||||
@ -218,7 +218,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should throw an error if recordInput contains fields unrelated to the current objectMetadata', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
@ -240,7 +240,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should throw an error if recordInput contains both the relationFieldId and relationField', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
@ -260,7 +260,7 @@ describe('computeOptimisticRecordFromInput', () => {
|
||||
|
||||
it('should throw an error if recordInput contains both the relationFieldId and relationField even if null', () => {
|
||||
const cache = new InMemoryCache();
|
||||
const personObjectMetadataItem = getPersonObjectMetadataItem();
|
||||
const personObjectMetadataItem = getMockPersonObjectMetadataItem();
|
||||
|
||||
expect(() =>
|
||||
computeOptimisticRecordFromInput({
|
||||
|
||||
Reference in New Issue
Block a user