Skip to content

Commit

Permalink
Fix editing records from record modal
Browse files Browse the repository at this point in the history
There was a bad condition in parsing the type of record from the record attributes

resolves #932
  • Loading branch information
paustint committed Jun 13, 2024
1 parent 8b0c509 commit b2cd951
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions libs/shared/utils/src/lib/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getMapFromObj,
getRecordIdFromAttributes,
getSObjectFromRecordUrl,
getSObjectNameFromAttributes,
groupByFlat,
multiWordObjectFilter,
multiWordStringFilter,
Expand Down Expand Up @@ -1125,3 +1126,41 @@ describe('utils.getRecordIdFromAttributes', () => {
expect(recordId).toEqual('');
});
});

describe('utils.getRecordIdFromAttributes', () => {
it('gets record id from attributes', () => {
expect(
getRecordIdFromAttributes({
attributes: { type: 'Opportunity', url: '/services/data/v60.0/sobjects/Opportunity/0068c00000lbXugAAE' },
})
).toBe('0068c00000lbXugAAE');
});

it('returns empty string if no url', () => {
expect(
getRecordIdFromAttributes({
attributes: { type: 'Opportunity', url: null },
})
).toBe('');
});
});

describe('utils.getSObjectNameFromAttributes', () => {
it('gets sobject name from type if available', () => {
expect(
getSObjectNameFromAttributes({
attributes: { type: 'Opportunity', url: null },
})
).toBe('Opportunity');
});
it('gets sobject name from attribute url', () => {
expect(
getSObjectNameFromAttributes({
attributes: { url: '/services/data/v60.0/sobjects/Opportunity/0068c00000lbXugAAE' },
})
).toBe('Opportunity');
});
it('returns empty string if no match', () => {
expect(getSObjectNameFromAttributes({})).toBe('');
});
});
2 changes: 1 addition & 1 deletion libs/shared/utils/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export function getRecordIdFromAttributes(record: any) {
}

export function getSObjectNameFromAttributes(record: any) {
if (!record?.attributes?.url) {
if (!record?.attributes?.type && !record?.attributes?.url) {
return '';
}
const urlWithoutId = record.attributes.type || record.attributes.url.substring(0, record.attributes.url.lastIndexOf('/'));
Expand Down

0 comments on commit b2cd951

Please sign in to comment.