mirror of
https://github.com/we-promise/sure.git
synced 2026-05-29 15:34:58 +00:00
feat(imports): verify Sure NDJSON import readback (#1869)
* feat(imports): verify Sure NDJSON readback * fix(imports): tighten Sure readback verification * fix(imports): polish Sure verification review nits
This commit is contained in:
@@ -120,6 +120,47 @@ class Api::V1::ImportsControllerTest < ActionDispatch::IntegrationTest
|
||||
json_response["data"]["stats"]["unassigned_mappings_count"]
|
||||
end
|
||||
|
||||
test "should show Sure import verification" do
|
||||
sure_import = @family.imports.create!(type: "SureImport")
|
||||
sure_import.ndjson_file.attach(
|
||||
io: StringIO.new(build_ndjson([
|
||||
{ type: "Account", data: {
|
||||
id: "account-1",
|
||||
name: "API Verified Checking",
|
||||
balance: "100.00",
|
||||
currency: "USD",
|
||||
accountable_type: "Depository"
|
||||
} },
|
||||
{ type: "Valuation", data: {
|
||||
id: "valuation-1",
|
||||
account_id: "account-1",
|
||||
date: "2024-01-14",
|
||||
amount: "100.00",
|
||||
currency: "USD",
|
||||
kind: "opening_anchor"
|
||||
} }
|
||||
])),
|
||||
filename: "sure.ndjson",
|
||||
content_type: "application/x-ndjson"
|
||||
)
|
||||
sure_import.sync_ndjson_rows_count!
|
||||
sure_import.publish
|
||||
|
||||
get api_v1_import_url(sure_import), headers: api_headers(@api_key)
|
||||
|
||||
assert_response :success
|
||||
json_response = JSON.parse(response.body)
|
||||
verification = json_response.dig("data", "verification")
|
||||
|
||||
assert_equal 1, verification.dig("expected_record_counts", "accounts")
|
||||
assert_equal 1, verification.dig("expected_record_counts", "valuations")
|
||||
assert_equal "matched", verification.dig("readback", "status")
|
||||
assert_equal 1, verification.dig("readback", "actual_delta_counts", "accounts")
|
||||
assert_equal 1, verification.dig("readback", "actual_delta_counts", "valuations")
|
||||
assert_equal 0, verification.dig("readback", "checked_counts", "balances")
|
||||
assert_empty verification.dig("readback", "mismatches")
|
||||
end
|
||||
|
||||
test "should list sanitized import row diagnostics" do
|
||||
get rows_api_v1_import_url(@diagnostic_import), headers: api_headers(@read_only_api_key)
|
||||
|
||||
@@ -1183,6 +1224,10 @@ class Api::V1::ImportsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
private
|
||||
|
||||
def build_ndjson(records)
|
||||
records.map(&:to_json).join("\n")
|
||||
end
|
||||
|
||||
def api_headers(api_key)
|
||||
{ "X-Api-Key" => api_key.plain_key }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user