The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
import { getTestEnrichedObjectMetadataItemsMock } from '~/testing/utils/getTestEnrichedObjectMetadataItemsMock';
import { normalizeGQLQuery } from '~/testing/utils/normalizeGQLQuery';
const personObjectMetadataItem = getTestEnrichedObjectMetadataItemsMock().find(
(item) => item.nameSingular === 'person',
);
if (!personObjectMetadataItem) {
throw new Error('Object metadata not found');
}
describe('mapObjectMetadataToGraphQLQuery', () => {
it('should query only specified recordGqlFields', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: getTestEnrichedObjectMetadataItemsMock(),
objectMetadataItem: personObjectMetadataItem,
recordGqlFields: {
company: true,
xLink: true,
id: true,
createdAt: true,
city: true,
email: true,
jobTitle: true,
name: true,
phone: true,
linkedinLink: true,
updatedAt: true,
avatarUrl: true,
companyId: true,
},
objectPermissionsByObjectMetadataId: {
[personObjectMetadataItem.id]: {
canReadObjectRecords: true,
canUpdateObjectRecords: true,
canSoftDeleteObjectRecords: true,
canDestroyObjectRecords: true,
objectMetadataId: personObjectMetadataItem.id,
restrictedFields: {},
rowLevelPermissionPredicates: [],
rowLevelPermissionPredicateGroups: [],
},
},
});
expect(normalizeGQLQuery(res)).toEqual(
normalizeGQLQuery(`{
__typename
name
{
firstName
lastName
}
emails
{
primaryEmail
additionalEmails
}
phone
{
primaryPhoneNumber
primaryPhoneCountryCode
primaryPhoneCallingCode
}
createdAt
avatarUrl
jobTitle
city
id
xLink
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks {
label
url
}
}
company
{
__typename
idealCustomerProfile
id
xLink
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks {
label
url
}
}
annualRecurringRevenue
{
amountMicros
currencyCode
}
address
{
addressStreet1
addressStreet2
addressCity
addressState
addressCountry
addressPostcode
addressLat
addressLng
}
employees
position
name
linkedinLink
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks {
label
url
}
}
createdAt
accountOwnerId
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks {
label
url
}
}
updatedAt
}
updatedAt
companyId
linkedinLink
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks {
label
url
}
}
}`),
);
});
it('should load only specified operation fields nested', async () => {
const res = mapObjectMetadataToGraphQLQuery({
objectMetadataItems: getTestEnrichedObjectMetadataItemsMock(),
objectMetadataItem: personObjectMetadataItem,
recordGqlFields: { company: { id: true }, id: true, name: true },
objectPermissionsByObjectMetadataId: {
[personObjectMetadataItem.id]: {
canReadObjectRecords: true,
canUpdateObjectRecords: true,
canSoftDeleteObjectRecords: true,
canDestroyObjectRecords: true,
objectMetadataId: personObjectMetadataItem.id,
restrictedFields: {},
rowLevelPermissionPredicates: [],
rowLevelPermissionPredicateGroups: [],
},
},
});
expect(normalizeGQLQuery(res)).toEqual(
normalizeGQLQuery(`{
__typename
id
company
{
__typename
id
}
name
{
firstName
lastName
}
}`),
);
});
});