Skip to content

Commit e1eb16b

Browse files
fix(record): remove Number() coercion in reload and destroyRecord to support string ids (#246)
* fix(record): remove Number() coercion in reload and destroyRecord to support string ids * fix(record): remove Number() coercion in reload and destroyRecord to support string ids
1 parent 418c72a commit e1eb16b

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

packages/dist/arm-js-library.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ Fix: Try adding ${collectionName} on your ARM config initialization.`;
572572
return this._request({
573573
resourceMethod: "delete",
574574
resourceName: getProperty(currentRecord, "collectionName"),
575-
resourceId: Number(getProperty(currentRecord, "id")),
575+
resourceId: getProperty(currentRecord, "id"),
576576
resourceParams: {},
577577
resourcePayload: null,
578578
resourceFallback: {},
@@ -593,7 +593,7 @@ Fix: Try adding ${collectionName} on your ARM config initialization.`;
593593
return this._request({
594594
resourceMethod: "get",
595595
resourceName: getProperty(currentRecord, "collectionName"),
596-
resourceId: Number(getProperty(currentRecord, "id")),
596+
resourceId: getProperty(currentRecord, "id"),
597597
resourceParams: {},
598598
resourcePayload: null,
599599
resourceFallback: {},

packages/src/lib/api-resource-manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ export default class ApiResourceManager {
715715
return this._request({
716716
resourceMethod: 'delete',
717717
resourceName: getProperty(currentRecord, 'collectionName'),
718-
resourceId: Number(getProperty(currentRecord, 'id')),
718+
resourceId: getProperty(currentRecord, 'id'),
719719
resourceParams: {},
720720
resourcePayload: null,
721721
resourceFallback: {},
@@ -737,7 +737,7 @@ export default class ApiResourceManager {
737737
return this._request({
738738
resourceMethod: 'get',
739739
resourceName: getProperty(currentRecord, 'collectionName'),
740-
resourceId: Number(getProperty(currentRecord, 'id')),
740+
resourceId: getProperty(currentRecord, 'id'),
741741
resourceParams: {},
742742
resourcePayload: null,
743743
resourceFallback: {},

packages/tests/mirage/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export default function () {
4646
: request.requestBody
4747
})
4848

49-
this.delete('/addresses/:id', () => {
50-
return { data: addresses.data[1] }
49+
this.delete('/addresses/:id', (schema, request) => {
50+
const { id } = request.params
51+
return isNaN(Number(id))
52+
? { data: { id, type: 'addresses', attributes: {} } }
53+
: { data: addresses.data[1] }
5154
})
5255
},
5356
})

packages/tests/units/record.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ const execRecordTest = (ARM) => {
158158
expect(record.get('attributes.address1')).toBe('Anabu Hills Test 4')
159159
})
160160

161+
test('Verify reload with string collection record id', async () => {
162+
ARM.pushPayload('addresses', [
163+
{
164+
id: 'JO-26181S4VPU65',
165+
type: 'addresses',
166+
attributes: { address1: 'String ID Address', kind: 'office' },
167+
},
168+
])
169+
const record = ARM.peekRecord('addresses', 'JO-26181S4VPU65')
170+
expect(record).toBeDefined()
171+
172+
const result = await record.reload()
173+
expect(result).toBeDefined()
174+
expect(record.get('isError')).toBe(false)
175+
})
176+
161177
test('Verify rollbackAttributes functionality', async () => {
162178
await ARM.findRecord('addresses', 2518368, null, {
163179
autoResolve: false,
@@ -204,6 +220,22 @@ const execRecordTest = (ARM) => {
204220
expect(ARM.peekRecord('addresses', 2518368)).toBeUndefined()
205221
})
206222

223+
test('Verify destroyRecord with string collection record id', async () => {
224+
ARM.pushPayload('addresses', [
225+
{
226+
id: 'JO-26181S4VPU65',
227+
type: 'addresses',
228+
attributes: { address1: 'String ID Address', kind: 'office' },
229+
},
230+
])
231+
const record = ARM.peekRecord('addresses', 'JO-26181S4VPU65')
232+
expect(record).toBeDefined()
233+
234+
const result = await record.destroyRecord()
235+
expect(result).toBeDefined()
236+
expect(ARM.peekRecord('addresses', 'JO-26181S4VPU65')).toBeUndefined()
237+
})
238+
207239
test('Verify getCollection functionality', async () => {
208240
await ARM.query(
209241
'addresses',

0 commit comments

Comments
 (0)