Skip to content

Commit

Permalink
fixed broken cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
qcdyx committed Mar 12, 2024
1 parent a22555c commit c14b92c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stg_web_svc_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Web service staging CD
on:
push:
branches:
- master
- 1689-web-validator-app-consumes-execution_resultsjson
workflow_dispatch:

env:
Expand Down
157 changes: 96 additions & 61 deletions web/client/cypress/e2e/error_messages.cy.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
/// <reference types="cypress" />

const url = 'https://developers.google.com/static/transit/gtfs/examples/sample-feed.zip';
const url =
'https://developers.google.com/static/transit/gtfs/examples/sample-feed.zip';
const jobId = '8f6be6fb-1fee-41f8-b401-b2b4b552e177-sample';

context('GTFS Validator - Confirm error messaging', () => {

it('Confirm error "Error authorizing upload"', () => {
// Setup intercept aliases
cy.intercept(
'POST',
`${Cypress.env("PUBLIC_CLIENT_API_ROOT")}/create-job`,
`${Cypress.env('PUBLIC_CLIENT_API_ROOT')}/create-job`,
{ forceNetworkError: true }
)
.as('createJob');
).as('createJob');

cy.visit('/')
cy.visit('/');

// Upload .zip file
cy.get('input#file')
.selectFile('cypress/fixtures/sample-feed.zip', { force: true });
cy.get('input#file').selectFile('cypress/fixtures/sample-feed.zip', {
force: true,
});

// Submit
cy.get('button[type=submit]')
.click();
cy.get('button[type=submit]').click();

// Wait for response error
cy.wait('@createJob');
Expand All @@ -39,34 +38,33 @@ context('GTFS Validator - Confirm error messaging', () => {
'PUT',
`https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`,
{ forceNetworkError: true }
)
.as('putFile');
).as('putFile');

cy.intercept(
'POST',
`${Cypress.env("PUBLIC_CLIENT_API_ROOT")}/create-job`,
`${Cypress.env('PUBLIC_CLIENT_API_ROOT')}/create-job`,
(req) => {
req.reply({
statusCode: 200,
statusMessage: "OK",
statusMessage: 'OK',
headers: {
"access-control-allow-origin": '*',
"Access-Control-Allow-Credentials": "true",
'access-control-allow-origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
body: {
jobId: jobId,
url: `https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`
}
url: `https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`,
},
});
}
)
.as('createJob');
).as('createJob');

cy.visit('/')
cy.visit('/');

// Upload .zip file
cy.get('input#file')
.selectFile('cypress/fixtures/sample-feed.zip', { force: true });
cy.get('input#file').selectFile('cypress/fixtures/sample-feed.zip', {
force: true,
});

// Submit
cy.get('button[type=submit]').click();
Expand All @@ -82,36 +80,71 @@ context('GTFS Validator - Confirm error messaging', () => {
.and('contain.text', 'Error uploading file');
});

// it('Confirm error "Error processing report"', () => {
// // Setup intercept aliases
// cy.intercept(
// 'POST',
// `${Cypress.env('PUBLIC_CLIENT_API_ROOT')}/create-job`,
// (req) => {
// req.reply({
// statusCode: 200,
// statusMessage: 'OK',
// headers: {
// 'access-control-allow-origin': '*',
// 'Access-Control-Allow-Credentials': 'true',
// },
// body: {
// jobId: jobId,
// url: `https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`,
// },
// });
// }
// ).as('createJob');

let shouldFail = false;

it('Confirm error "Error processing report"', () => {
// Setup intercept aliases
cy.intercept(
'POST',
`${Cypress.env("PUBLIC_CLIENT_API_ROOT")}/create-job`,
`${Cypress.env('PUBLIC_CLIENT_API_ROOT')}/create-job`,
(req) => {
req.reply({
statusCode: 200,
statusMessage: "OK",
headers: {
"access-control-allow-origin": '*',
"Access-Control-Allow-Credentials": "true",
},
body: {
jobId: jobId,
url: `https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`
}
});
if (shouldFail) {
req.reply({
statusCode: 500,
statusMessage: 'Internal Server Error',
headers: {
'access-control-allow-origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
body: {
error: 'Error processing report.',
},
});
} else {
req.reply({
statusCode: 200,
statusMessage: 'OK',
headers: {
'access-control-allow-origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
body: {
jobId: jobId,
url: `https://storage.googleapis.com/stg-validator-user-uploads/${jobId}/gtfs-job.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256`,
},
});
}
}
)
.as('createJob');
).as('awaitJob');

cy.intercept(
'HEAD',
`${Cypress.env("PUBLIC_CLIENT_REPORTS_ROOT")}/*/report.html`,
`${Cypress.env('PUBLIC_CLIENT_REPORTS_ROOT')}/*/report.html`,
{ forceNetworkError: true }
)
.as('awaitJob');
).as('awaitJob');

cy.visit('/')
cy.visit('/');

// Enter URL to .zip file
cy.get('input#url').type(url);
Expand All @@ -132,33 +165,35 @@ context('GTFS Validator - Confirm error messaging', () => {

it('Confirm error "HTTP Error: 404"', () => {
// Setup intercept aliases
cy.intercept(
'rules.json',
(req) => {
req.reply({
statusCode: 404,
headers: {
"access-control-allow-origin": '*',
"Access-Control-Allow-Credentials": "true",
},
});
}
)
.as('getDocMarkdown');

cy.visit('/')
cy.intercept('rules.json', (req) => {
req.reply({
statusCode: 404,
headers: {
'access-control-allow-origin': '*',
'Access-Control-Allow-Credentials': 'true',
},
});
}).as('getDocMarkdown');

cy.visit('/');

// Click "See Documentation" button
cy.get('a:contains("See Documentation")').click();

cy.location('pathname', {timeout: 60000}).should('include', '/rules.html');

cy.location('pathname', { timeout: 60000 }).should(
'include',
'/rules.html'
);

// Confirm error content
cy.get('.container .markdown')
.should('be.visible')
.within((div) => {
cy.get('h1').should('contain.text', 'HTTP Error: 404');
cy.get('p').should('contain.text', 'There was a problem loading the rules file.');
})
cy.get('p').should(
'contain.text',
'There was a problem loading the rules file.'
);
});
});
});

0 comments on commit c14b92c

Please sign in to comment.