From 65228370c513ebcf0afa70c84e875b090212a4a7 Mon Sep 17 00:00:00 2001 From: Vivian Ha Date: Thu, 8 Aug 2024 12:04:27 -0400 Subject: [PATCH 1/4] [#805] Add Fixture with empty records Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg Co-authored-by: Winsice Ng --- .../records_no_offset_empty_records.json | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 spec/fixtures/files/air_table/records_no_offset_empty_records.json diff --git a/spec/fixtures/files/air_table/records_no_offset_empty_records.json b/spec/fixtures/files/air_table/records_no_offset_empty_records.json new file mode 100644 index 00000000..f439347b --- /dev/null +++ b/spec/fixtures/files/air_table/records_no_offset_empty_records.json @@ -0,0 +1,42 @@ +{ + "records": [ + { + "id": "recrhIUhcJw3Owio92", + "createdTime": "2024-01-30T22:16:16.000Z", + "fields": { + } + }, + { + "id": "recrhIUhcJwsoiw21", + "createdTime": "2024-01-30T22:16:16.000Z", + "fields": { + "fldbnDHHhDNlc2Lx8": "ab123@princeton.edu", + "fld4JloN0LxiFaTiw": "Hello\nMy research interests\nare\n\nfantastic!", + "fldULoOUDSpoEpdAP": "https://example.com", + "fldXw9janMHvhBWvO": ["Industrial Relations", "James Madison Program"] + } + }, + { + "id": "recrhIUhcJw3dW022", + "createdTime": "2024-01-30T22:16:16.000Z", + "fields": { + "fldKZxmtofNbXW4qS": "123 Stokes", + "fldCCTbVNKKBFXxrp": ["Virtual Reality"], + "fldxpCzkJmhEkVqZt": "Special and Distinctive Collections", + "fld9NYFQePrPxbJJW": "Special Collections", + "fldz6yBenvTjdClXZ": "Stokes", + "fldvENk2uiLDHmYSw": "Librarian", + "fldnKprqGraSvNTJK": "Phillip", + "fldw0mjDdB48HstnB": "Library Collections Specialist V", + "fldbquJ6Hn2eq1V2h": "123", + "fldgarsg3FzD8xpE4": "ab123", + "fldqulY6ehd5aIbR1": "(123) 123-1234", + "fldL7tm4jVvYksIwl": "Phillip Librarian", + "fldbnDHHhDNlc2Lx8": "ab123@princeton.edu", + "fld4JloN0LxiFaTiw": "Hello\nMy research interests\nare\n\nfantastic!", + "fldULoOUDSpoEpdAP": "https://example.com", + "fldXw9janMHvhBWvO": ["Industrial Relations", "James Madison Program"] + } + } + ] +} \ No newline at end of file From 40daeb21f6f9b11d668bb78650b8404f0811f1fd Mon Sep 17 00:00:00 2001 From: Winsice Ng Date: Thu, 8 Aug 2024 12:27:03 -0400 Subject: [PATCH 2/4] [#805] Add empty condition for stub_airtable and test for when airtable contains empty records Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg Co-authored-by: Vivian Ha --- spec/models/air_table_staff/record_list_spec.rb | 10 ++++++++++ spec/support/stub_airtable.rb | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/models/air_table_staff/record_list_spec.rb b/spec/models/air_table_staff/record_list_spec.rb index 46c1599d..0e4daf60 100644 --- a/spec/models/air_table_staff/record_list_spec.rb +++ b/spec/models/air_table_staff/record_list_spec.rb @@ -58,4 +58,14 @@ end end end + context 'when the airtable contains empty records' do + before do + stub_airtable(empty: true) + end + it 'does not include empty records' do + list = described_class.new.to_a + + expect(list.length).to eq(1) + end + end end diff --git a/spec/support/stub_airtable.rb b/spec/support/stub_airtable.rb index e745c80b..5fafa884 100644 --- a/spec/support/stub_airtable.rb +++ b/spec/support/stub_airtable.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true module AirtableStubbing BASE_AIRTABLE_URL = "https://api.airtable.com/v0/appv7XA5FWS7DG9oe/tblM0iymGN5oqDUVm?fields%5B%5D=fld0MfgMlZd364YTR&fields%5B%5D=fld4JloN0LxiFaTiw&fields%5B%5D=fld9NYFQePrPxbJJW&fields%5B%5D=fldCCTbVNKKBFXxrp&fields%5B%5D=fldGzh0SHZqlFk3aU&fields%5B%5D=fldKZxmtofNbXW4qS&fields%5B%5D=fldnKprqGraSvNTJK&fields%5B%5D=fldL7tm4jVvYksIwl&fields%5B%5D=fldULoOUDSpoEpdAP&fields%5B%5D=fldXw9janMHvhBWvO&fields%5B%5D=fldbnDHHhDNlc2Lx8&fields%5B%5D=fldbquJ6Hn2eq1V2h&fields%5B%5D=fldvENk2uiLDHmYSw&fields%5B%5D=fldgarsg3FzD8xpE4&fields%5B%5D=fldqulY6ehd5aIbR1&fields%5B%5D=fldusiuPpfSql6vSk&fields%5B%5D=fldw0mjDdB48HstnB&fields%5B%5D=fldxpCzkJmhEkVqZt&fields%5B%5D=fldypTXdkQGpYgVDC&fields%5B%5D=fldz6yBenvTjdClXZ&returnFieldsByFieldId=true" - def stub_airtable(offset: false) + def stub_airtable(offset: false, empty: false) if offset stub_airtable_with_offset + elsif empty + stub_airtable_without_offset_empty_records else stub_airtable_without_offset end @@ -33,6 +35,15 @@ def stub_airtable_without_offset }) .to_return(status: 200, body: File.read(airtable_path)) end + + def stub_airtable_without_offset_empty_records + airtable_path = Pathname.new(file_fixture_path).join("air_table", 'records_no_offset_empty_records.json') + stub_request(:get, BASE_AIRTABLE_URL) + .with(headers: { + 'Authorization' => 'Bearer FAKE_AIRTABLE_TOKEN' + }) + .to_return(status: 200, body: File.read(airtable_path)) + end end RSpec.configure do |config| From c8837bc19fa4c765d9c8e129692e75cff484d386 Mon Sep 17 00:00:00 2001 From: Winsice Ng Date: Tue, 13 Aug 2024 12:30:07 -0400 Subject: [PATCH 3/4] [#805] Add json_records to select non-empty fields to record_list.rb Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg Co-authored-by: Vivian Ha --- app/models/air_table_staff/record_list.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/air_table_staff/record_list.rb b/app/models/air_table_staff/record_list.rb index f5f0fcb0..ba81f60d 100644 --- a/app/models/air_table_staff/record_list.rb +++ b/app/models/air_table_staff/record_list.rb @@ -27,7 +27,8 @@ def base_url def to_a(offset: nil) @as_array ||= begin json = get_json(offset:) - records = json[:records].map do |row| + json_records = json[:records].select { |record| record[:fields].present? && (record[:fields][:fldvENk2uiLDHmYSw] || record[:fields][:fldnKprqGraSvNTJK]) } + records = json_records.map do |row| AirTableStaff::StaffDirectoryPerson.new(row[:fields]) end offset = json[:offset] From 57f877f2d8b9900bfd4fe938eb4db9e28c580bf0 Mon Sep 17 00:00:00 2001 From: Vivian Ha Date: Tue, 13 Aug 2024 12:49:48 -0400 Subject: [PATCH 4/4] [#805] Log empty records Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg Co-authored-by: Winsice Ng --- app/models/air_table_staff/record_list.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/air_table_staff/record_list.rb b/app/models/air_table_staff/record_list.rb index ba81f60d..d73df4a5 100644 --- a/app/models/air_table_staff/record_list.rb +++ b/app/models/air_table_staff/record_list.rb @@ -27,7 +27,11 @@ def base_url def to_a(offset: nil) @as_array ||= begin json = get_json(offset:) - json_records = json[:records].select { |record| record[:fields].present? && (record[:fields][:fldvENk2uiLDHmYSw] || record[:fields][:fldnKprqGraSvNTJK]) } + json_records = json[:records].select do |record| + record_present = record[:fields].present? && (record[:fields][:fldvENk2uiLDHmYSw] || record[:fields][:fldnKprqGraSvNTJK]) + Rails.logger.error("This record #{record[:fields]} is missing first and/or last name. It will not be included.") unless record_present + record_present + end records = json_records.map do |row| AirTableStaff::StaffDirectoryPerson.new(row[:fields]) end