diff --git a/README.md b/README.md index 8717fc2..febd54d 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,7 @@ orca.fields.delete('sheet-id', 'field-key').then(function(result) { | `readonlyMobile` | `boolean` | Prevent user input on mobile *(default: false)* | | `useInMobileSearch` | `boolean` | Include value in mobile search *(default: false)* | | `useValueInList` | `boolean` | Show field value in mobile list *(default: false)* | +| `index` | `integer` | Display order of the field *(default: -1)* | #### Field formats diff --git a/index.js b/index.js index bc7d969..270b228 100644 --- a/index.js +++ b/index.js @@ -413,6 +413,7 @@ function OrcaScanNode(apiKey, options) { * @param {boolean} [payload.readonlyMobile=false] - if true, field is read-only on mobile * @param {boolean} [payload.useInMobileSearch=true] - if true, field is searchable in mobile list * @param {boolean} [payload.useValueInList=true] - if true, field is visible in mobile list + * @param {number} [payload.index] - if provided, sets the display order of the field * @returns {Promise} promise resolving to result * {object} data - created field with all properties */ @@ -444,6 +445,7 @@ function OrcaScanNode(apiKey, options) { * @param {boolean} [payload.readonlyMobile] - if true, field is read-only on mobile * @param {boolean} [payload.useInMobileSearch] - if true, field is searchable in mobile list * @param {boolean} [payload.useValueInList] - if true, field is visible in mobile list + * @param {number} [payload.index] - if provided, sets the display order of the field * @returns {Promise} promise resolving to result * {object} data - updated field with all properties */ diff --git a/package-lock.json b/package-lock.json index 4a5b797..3a719bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@orca-scan/orca-scan-node", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 188effd..6e324b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orca-scan/orca-scan-node", - "version": "1.1.0", + "version": "1.1.1", "engines": { "node": ">=14.16.0" }, diff --git a/tests/e2e/03-fields-e2e-spec.js b/tests/e2e/03-fields-e2e-spec.js index 238cef6..6b39793 100644 --- a/tests/e2e/03-fields-e2e-spec.js +++ b/tests/e2e/03-fields-e2e-spec.js @@ -35,6 +35,29 @@ describe('e2e: fields', function () { expect(found.label).toBe('E2E Notes Updated'); }); + it('should create a field with a specific index', async function () { + var field = await client.fields.create(setup.getSheetId(), { + label: 'E2E Indexed Field', + format: 'text', + index: 2 + }); + + expect(field).toBeDefined(); + expect(field.label).toBe('E2E Indexed Field'); + expect(field.index).toBe(2); + + // clean up + await client.fields.delete(setup.getSheetId(), field.key); + }); + + it('should update a field index', async function () { + var updated = await client.fields.update(setup.getSheetId(), fieldKey, { + index: 1 + }); + + expect(updated.index).toBe(1); + }); + it('should delete the field', async function () { await client.fields.delete(setup.getSheetId(), fieldKey); diff --git a/tests/fields-spec.js b/tests/fields-spec.js index bf60154..5a800c4 100644 --- a/tests/fields-spec.js +++ b/tests/fields-spec.js @@ -87,6 +87,21 @@ describe('Fields', function() { }); }); + it('should create a field with index in payload', function() { + var payload = { label: 'Test Field', format: 'text', index: 2 }; + + return client.fields.create('test-sheet-id', payload).then(function(result) { + expect(mockFetch).toHaveBeenCalledWith( + 'https://api.orcascan.com/v1/sheets/test-sheet-id/fields', + jasmine.objectContaining({ + method: 'POST', + body: JSON.stringify(payload) + }) + ); + expect(result).toBeDefined(); + }); + }); + it('should create a field with all optional properties', function() { var sheetId = 'test-sheet-id'; var payload = { @@ -198,6 +213,21 @@ describe('Fields', function() { }); }); + it('should update a field with index in payload', function() { + var payload = { label: 'Updated Field Label', index: 1 }; + + return client.fields.update('test-sheet-id', 'test-field', payload).then(function(result) { + expect(mockFetch).toHaveBeenCalledWith( + 'https://api.orcascan.com/v1/sheets/test-sheet-id/fields/test-field', + jasmine.objectContaining({ + method: 'PUT', + body: JSON.stringify(payload) + }) + ); + expect(result).toBeDefined(); + }); + }); + it('should throw error when updating field without sheetId', function() { expect(function() { client.fields.update();