-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://eaflood.atlassian.net/jira/software/projects/CMEA/boards/907?selectedIssue=CMEA-282 In `cypress/integration/common/read_export.js` we create an example `When` step which can read a given export file from an S3 bucket, and example `Then` steps which check the value of the item at a given row/column, or check that a value exists in a specified column. In `cypress/integration/legacy/cfd/cfd_steps.js` we update the `I see confirmation the transaction file is queued for export` step to capture the name of the queued file, and create `I log the transaction filename to prove it can be used in another step` as an example of how we access it from another step.⚠️ Note that the environment variable `CYPRESS_S3_PATH` (the path we upload import files to) is now changed to `CYPRESS_S3_UPLOAD_PATH` so will need to be updated in existing environment files. We have created an additional `CYPRESS_S3_DOWNLOAD_PATH` which is the path we will download export files from. * Rename existing S3 env var We currently have an environment variable `CYPRESS_S3_PATH`, which we use to specify the folder files should be uploaded to. Since we want to be able to specify separate paths for uploading and downloading, we therefore rename this to `CYPRESS_S3_UPLOAD_PATH` * Create initial `s3Download` task We start by creatin a basic `s3Download` task which simply reads the specified file and logs its contents to the Cypress console. * Complete feature We develop the read export feature to take the file data returned by `s3Download` and split it into a 2-dimensional array. We can then retrieve the item at a given row and column. * Edit comment * Write `column contains` step We write a step which allows us to check that the specified column has a particular value somewhere in it * Develop legacy cfd steps In the legacy cfd tests, we update the export file confirmation step to retrieve the filename and store it, and create an additional step which demonstrates how to retrieve the stored filename * Update `read_export` to use `cy.wrap` Having realised that `cy.wrap` is preferable to defining variables, we upddate the steps in `read_export` * Add `CYPRESS_S3_DOWNLOAD_PATH` to `.example.env`
- Loading branch information
Showing
7 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Then, When } from 'cypress-cucumber-preprocessor/steps' | ||
|
||
When('I read the export file {string}', (filePath) => { | ||
cy.task('s3Download', { | ||
Bucket: Cypress.env('S3_BUCKET'), | ||
remotePath: Cypress.env('S3_DOWNLOAD_PATH'), | ||
filePath | ||
}).then(data => { | ||
cy.wrap(splitData(data)).as('exportData') | ||
}) | ||
}) | ||
|
||
Then('row {int} column {int} equals {string}', (row, column, value) => { | ||
cy.get('@exportData') | ||
.then(exportData => expect(exportData[row][column]).to.equal(value)) | ||
}) | ||
|
||
Then('column {int} contains {string}', (column, value) => { | ||
cy.get('@exportData') | ||
.then(exportData => { | ||
const columnData = exportData.map(row => row[column]) | ||
expect(columnData).to.include(value) | ||
}) | ||
}) | ||
|
||
/** | ||
* Splits the data into a two-dimensional array, removing the double quotes that normally enclose each item. | ||
*/ | ||
function splitData (data, row, column) { | ||
return data | ||
// Split the data into an array of lines | ||
.split('\n') | ||
// Split each line into an array of items, and use regex replace to remove enclosing quotes from each item. | ||
// https://thispointer.com/remove-first-and-last-double-quotes-from-a-string-in-javascript/ | ||
.map(line => line | ||
.split(',') | ||
.map(item => item.replace(/(^"|"$)/g, '')) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Read Export Files | ||
|
||
Scenario: Read export file | ||
When I read the export file 'wrls/transaction/nalwi50001.dat' | ||
Then row 0 column 0 equals 'H' | ||
Then row 1 column 1 equals '0000001' | ||
Then column 2 contains 'A51541393A' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters