Three tiny CSV fixtures that catch different importer mistakes
A well-formed CSV can still carry the wrong meaning for your importer. Here are three fictional inputs, with explicit expectations, that you can copy into a test suite without uploading any customer data. An identifier is a string id,postal_code 0007,00123 Expected cells: ["0007", "00123"] . If your application converts both values to integers, it has changed the identifiers. Whether to convert a…
One additional test case that has identified an importer bug in the reporter's suite involves a repeating ID. The CSV input is:
id,name
001,Ada
001,Jan
According to the CSV specification, an importer should fail this test case since the IDs are repeated. However, a tolerant importer that silently overwrites the previous record with the last occurrence of the ID could parse this as:
id,name
001,Jan
This behavior may appear correct at first glance, but it represents a business decision that should be explicitly stated in the importer's test suite. Recording the input's encoding and delimiter alongside each fixture aids in diagnosing the issue. While the CSV itself is technically valid, the importer's handling of the duplicate ID does not align with its intended purpose or the data's accuracy.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.