Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.12.4 #133

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog

## [v1.12.3](https://github.com/DFE-Digital/dfe-analytics/tree/v1.12.3) (2024-04-02)
## [v1.12.4](https://github.com/DFE-Digital/dfe-analytics/tree/v1.12.4) (2024-04-23)

[Full Changelog](https://github.com/DFE-Digital/dfe-analytics/compare/v1.12.3...v1.12.4)

**Merged pull requests:**

- Fix for flakey tests [\#134](https://github.com/DFE-Digital/dfe-analytics/pull/134) ([ericaporter](https://github.com/ericaporter))
- Explicitly truncate updated\_at and created\_at [\#132](https://github.com/DFE-Digital/dfe-analytics/pull/132) ([ericaporter](https://github.com/ericaporter))
- Add ImportEntityTableCheck to import task [\#131](https://github.com/DFE-Digital/dfe-analytics/pull/131) ([ericaporter](https://github.com/ericaporter))
- Add flags to prevent code running in envs where dfe-analytics isn't set up [\#130](https://github.com/DFE-Digital/dfe-analytics/pull/130) ([ericaporter](https://github.com/ericaporter))

## [v1.12.3](https://github.com/DFE-Digital/dfe-analytics/tree/v1.12.3) (2024-04-04)
>>>>>>> 21aad86 (v1.12.4)

[Full Changelog](https://github.com/DFE-Digital/dfe-analytics/compare/v1.12.2...v1.12.3)

Expand Down
60 changes: 32 additions & 28 deletions spec/dfe/analytics/services/entity_table_checks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,22 @@

describe '#call' do
let(:time_zone) { 'London' }
let(:checksum_calculated_at) { ActiveRecord::Base.connection.select_all('SELECT CURRENT_TIMESTAMP AS current_timestamp').first['current_timestamp'].in_time_zone(time_zone).iso8601(6) }
let(:order_column) { 'UPDATED_AT' }
let(:course_entity) { DfE::Analytics.entities_for_analytics.find { |entity| entity.to_s.include?('course') } }
let(:institution_entity) { DfE::Analytics.entities_for_analytics.find { |entity| entity.to_s.include?('institution') } }
let(:application_entity) { DfE::Analytics.entities_for_analytics.find { |entity| entity.to_s.include?('application') } }
let(:candidate_entity) { DfE::Analytics.entities_for_analytics.find { |entity| entity.to_s.include?('candidate') } }
let(:department_entity) { DfE::Analytics.entities_for_analytics.find { |entity| entity.to_s.include?('department') } }
let(:entity_type) { 'entity_table_check' }
let(:checksum_calculated_at) { @checksum_calculated_at }
let(:current_timestamp) do
ActiveRecord::Base.connection.select_all('SELECT CURRENT_TIMESTAMP AS current_timestamp').first['current_timestamp'].in_time_zone(time_zone)
end
let(:checksum_calculated_at) { current_timestamp.iso8601(6) }

before { Timecop.freeze(checksum_calculated_at) }
before do
Timecop.freeze(current_timestamp)
end
after { Timecop.return }

it 'returns if the adapter or environment is unsupported' do
Expand All @@ -92,7 +98,6 @@

it 'orders by created_at if updated_at is missing' do
order_column = 'CREATED_AT'

[123, 124, 125].map { |id| Application.create(id: id) }
application_entities = DfE::Analytics.entities_for_analytics.select { |entity| entity.to_s.include?('application') }
table_ids = Application.where('created_at < ?', checksum_calculated_at).order(created_at: :asc).pluck(:id)
Expand Down Expand Up @@ -120,42 +125,41 @@

candidate_entities.each do |candidate|
described_class.call(entity_name: candidate, entity_type: entity_type, entity_tag: nil)
expect(DfE::Analytics::SendEvents).to have_received(:perform_later)
.with([a_hash_including({
'data' =>
[
{ 'key' => 'row_count', 'value' => [table_ids.size] },
{ 'key' => 'checksum', 'value' => [checksum] },
{ 'key' => 'checksum_calculated_at', 'value' => [checksum_calculated_at] },
{ 'key' => 'order_column', 'value' => [order_column] }
]
})])
end
end

it 'does not send the event if updated_at is greater than checksum_calculated_at' do
Timecop.freeze(DateTime.parse(checksum_calculated_at)) do
Candidate.create(id: '123', updated_at: DateTime.parse(checksum_calculated_at) - 2.hours)
Candidate.create(id: '124', updated_at: DateTime.parse(checksum_calculated_at) - 5.hours)
Candidate.create(id: '125', updated_at: DateTime.parse(checksum_calculated_at) + 5.hours)

table_ids = Candidate.where('updated_at < ?', checksum_calculated_at).order(:updated_at).pluck(:id)
checksum = Digest::MD5.hexdigest(table_ids.join)

described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil)

expect(DfE::Analytics::SendEvents).to have_received(:perform_later)
.with([a_hash_including({
.with([hash_including({
'data' => [
{ 'key' => 'row_count', 'value' => [table_ids.size] },
{ 'key' => 'checksum', 'value' => [checksum] },
{ 'key' => 'checksum_calculated_at', 'value' => [checksum_calculated_at] },
{ 'key' => 'order_column', 'value' => [order_column] }
]
})])
})])
end
end

it 'does not send the event if updated_at is greater than checksum_calculated_at' do
Candidate.create(id: '123', updated_at: DateTime.parse(checksum_calculated_at) - 2.hours)
Candidate.create(id: '124', updated_at: DateTime.parse(checksum_calculated_at) - 5.hours)
Candidate.create(id: '125', updated_at: DateTime.parse(checksum_calculated_at) + 5.hours)

table_ids = Candidate.where('updated_at < ?', checksum_calculated_at).order(:updated_at).pluck(:id)
checksum = Digest::MD5.hexdigest(table_ids.join)

described_class.call(entity_name: candidate_entity, entity_type: entity_type, entity_tag: nil)
puts "@checksum_calculated_at set to #{checksum_calculated_at}" # Debugging output

expect(DfE::Analytics::SendEvents).to have_received(:perform_later)
.with([a_hash_including({
'data' => [
{ 'key' => 'row_count', 'value' => [table_ids.size] },
{ 'key' => 'checksum', 'value' => [checksum] },
{ 'key' => 'checksum_calculated_at', 'value' => [checksum_calculated_at] },
{ 'key' => 'order_column', 'value' => [order_column] }
]
})])
end

it 'returns zero rows and checksum if table is empty' do
table_ids = Candidate.where('updated_at < ?', checksum_calculated_at).order(updated_at: :asc).pluck(:id)
checksum = Digest::MD5.hexdigest(table_ids.join)
Expand Down
Loading