Skip to content

Commit 19cee36

Browse files
authored
Merge pull request #1 from usdigitalresponse/kevee/record-name-property
feat: track name as first field in a record
2 parents 656e30e + e7e02f4 commit 19cee36

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

Diff for: CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.0.2] - 2025-01-09
11+
12+
### Changed
13+
14+
- Changed the `name` property of records to pull data from the first field in the table.
15+
16+
## [0.0.1] - 2025-01-08
17+
18+
### Added
19+
20+
- Initial release.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-environment-airtable-script",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "A jest environment for testing Airtable scripts in extensions and automations",
55
"license": "Apache-2.0",
66
"author": "",

Diff for: src/environment/sdk/__sdk.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -8531,11 +8531,16 @@
85318531
class Record {
85328532
constructor(data, fields) {
85338533
this.id = data.id;
8534-
this.name = data.name || '';
85358534
this._cellValues = data.cellValuesByFieldId;
85368535
this._fields = fields;
85378536
this._accessibleFields = fields;
85388537
}
8538+
get name() {
8539+
if (!this._fields || !this._fields[0]) {
8540+
return '';
8541+
}
8542+
return this.getCellValueAsString(this._fields[0]);
8543+
}
85398544
/**
85408545
* Gets a field ID based on whether an item is a Field object, field ID, or field name.
85418546
*

Diff for: src/environment/sdk/globals/base/record/index.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ class Record {
1010
* The unique ID of this record.
1111
*/
1212
id: string
13-
/**
14-
* The primary cell value as a string, or 'Unnamed record' if primary cell value is empty.
15-
*/
16-
name: string
1713
/**
1814
* The raw cell values of this record.
1915
*/
@@ -33,12 +29,18 @@ class Record {
3329

3430
constructor(data: FixtureRecord, fields: Field[]) {
3531
this.id = data.id
36-
this.name = data.name || ''
3732
this._cellValues = data.cellValuesByFieldId
3833
this._fields = fields
3934
this._accessibleFields = fields
4035
}
4136

37+
get name(): string {
38+
if (!this._fields || !this._fields[0]) {
39+
return ''
40+
}
41+
return this.getCellValueAsString(this._fields[0])
42+
}
43+
4244
/**
4345
* Gets a field ID based on whether an item is a Field object, field ID, or field name.
4446
*

Diff for: src/environment/sdk/globals/base/record/record.test.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ describe('Record', () => {
99

1010
const data = {
1111
id: 'rec1',
12-
name: 'Test Record',
1312
cellValuesByFieldId: {
1413
fld1: 'Value 1',
1514
fld2: 'Value 2',
@@ -22,32 +21,32 @@ describe('Record', () => {
2221
record = new Record(data, fields)
2322
})
2423

25-
test('should create a record with correct id and name', () => {
24+
it('should create a record with correct id and name', () => {
2625
expect(record.id).toBe('rec1')
27-
expect(record.name).toBe('Test Record')
26+
expect(record.name).toBe('Value 1')
2827
})
2928

30-
test('should get cell value by a Field class', () => {
29+
it('should get cell value by a Field class', () => {
3130
expect(record.getCellValue(fields[0])).toBe('Value 1')
3231
expect(record.getCellValue(fields[1])).toBe('Value 2')
3332
})
3433

35-
test('should get cell value by field id', () => {
34+
it('should get cell value by field id', () => {
3635
expect(record.getCellValue('fld1')).toBe('Value 1')
3736
expect(record.getCellValue('fld2')).toBe('Value 2')
3837
})
3938

40-
test('should get cell value by field name', () => {
39+
it('should get cell value by field name', () => {
4140
expect(record.getCellValue('Field 1')).toBe('Value 1')
4241
expect(record.getCellValue('Field 2')).toBe('Value 2')
4342
})
4443

45-
test('should get cell value as string', () => {
44+
it('should get cell value as string', () => {
4645
expect(record.getCellValueAsString('fld1')).toBe('Value 1')
4746
expect(record.getCellValueAsString('fld2')).toBe('Value 2')
4847
})
4948

50-
test('should throw error if field not found', () => {
49+
it('should throw error if field not found', () => {
5150
expect(() => record.getCellValue('fld3')).toThrow(
5251
'No field matching "fld3" found in table'
5352
)

Diff for: src/environment/sdk/globals/output.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('automationOutput', () => {
66
__output.length = 0
77
})
88

9-
test('should set key and value', () => {
9+
it('should set key and value', () => {
1010
automationOutput.set('key1', 'value1')
1111
expect(__output).toEqual([{ key: 'key1', value: 'value1' }])
1212
})
@@ -17,17 +17,17 @@ describe('extensionOutput', () => {
1717
__output.length = 0
1818
})
1919

20-
test('should add text to output', () => {
20+
it('should add text to output', () => {
2121
extensionOutput.text('some text')
2222
expect(__output).toEqual(['some text'])
2323
})
2424

25-
test('should add markdown to output', () => {
25+
it('should add markdown to output', () => {
2626
extensionOutput.markdown('**some** markdown')
2727
expect(__output).toEqual(['**some** markdown'])
2828
})
2929

30-
test('should add table to output', () => {
30+
it('should add table to output', () => {
3131
const table = [
3232
['a', 1],
3333
['b', 2],
@@ -38,13 +38,13 @@ describe('extensionOutput', () => {
3838
])
3939
})
4040

41-
test('should add inspected object to output', () => {
41+
it('should add inspected object to output', () => {
4242
const obj = { key: 'value' }
4343
extensionOutput.inspect(obj)
4444
expect(__output).toEqual([JSON.stringify(obj)])
4545
})
4646

47-
test('should clear the output', () => {
47+
it('should clear the output', () => {
4848
extensionOutput.text('some text')
4949
extensionOutput.clear()
5050
expect(__output[0]).toEqual('some text')

0 commit comments

Comments
 (0)