From 21df4ce8be1f8d4086205e9105f7b019ce60f44a Mon Sep 17 00:00:00 2001 From: Felix Clack Date: Wed, 4 Sep 2024 09:42:30 +0100 Subject: [PATCH] Parse the date of birth field for a bulk search The API endpoint we use for the bulk search expects the date of birth field to be a date object. This change ensures we pass the value in the correct format. --- app/models/bulk_search.rb | 2 +- spec/models/bulk_search_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/bulk_search.rb b/app/models/bulk_search.rb index 66998cfd..8fc0397c 100644 --- a/app/models/bulk_search.rb +++ b/app/models/bulk_search.rb @@ -73,7 +73,7 @@ def find_all(queries) def response @response ||= begin - queries = csv.map { |row| { trn: row["TRN"], dateOfBirth: row["Date of birth"] } }.compact + queries = csv.map { |row| { trn: row["TRN"], dateOfBirth: Date.parse(row["Date of birth"]) } }.compact find_all(queries) end end diff --git a/spec/models/bulk_search_spec.rb b/spec/models/bulk_search_spec.rb index cd306152..486f0179 100644 --- a/spec/models/bulk_search_spec.rb +++ b/spec/models/bulk_search_spec.rb @@ -74,6 +74,20 @@ expect(call.third).to eq(["trn" => '3001403', "date_of_birth" => Date.parse('01/01/1990')]) end + it 'parses the date of birth correctly in the queries' do + expect_any_instance_of(QualificationsApi::Client).to receive(:bulk_teachers) do |_, queries:| + expect(queries).to include( + hash_including( + trn: '3001403', + dateOfBirth: Date.parse('01/01/1990') + ) + ) + { "results" => [], "total" => 0 } + end + + call + end + context 'when the bulk search is not valid' do let(:file) { nil } @@ -94,5 +108,7 @@ ]) end end + + end end \ No newline at end of file