Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@studyportals/bestfit-test

Package Overview
Dependencies
Maintainers
17
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@studyportals/bestfit-test

E2E testing code for the BestFit application

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
17
Weekly downloads
 
Created
Source

BestFit-Test

Table of Contents

About

BestFit-Test is an NPM package that contains end-to-end tests for all the BestFit front-end microservices. For the tests Cypress is used.

A list of the front-end microservices (and any BestFit services for that matter), can be found in the README of BestFit-Shared.

Getting started

Go to the right repository

The purpose of the tests included in this repository is to test the front-end microservices. Therefore, this repository stand-alone isn't a good starting point.

Therefore, the first step is to go to the repository of any of the front-end microservices. A list of the front-end microservices (and any BestFit services for that matter), can be found in the README of BestFit-Shared.

Get the BestFit-Test package

You need to make sure that the @studyportals/bestfit-test package is included in the microservice, alongside any other dependencies.

# Make sure it is installed by running:
npm install

Running the tests

There are two ways of running the tests.

Run all the tests in a headless browser

Run the following command in your console:

# Run all tests in the configured folder.
npm run cypress
Open an interface, in which you can select what to run

Run the following command in your console:

# Open the interface.
npx cypress open

This will take a while. A new window will open that will show you an overview of all the tests there are.

[Cypress screenshot]

Click on the test, and a new window will open that starts to run the tests. Or, instead, you can click on Run all specs to run all tests that are shown in the window.

Configuration

In the root of each of the BestFit front-end microservices you can find configuration that is used to determine which tests are run and how, inside the cypress.json file. The two most important json properties to consider are:

  • integrationFolder: The folder location that Cypress looks at to retrieve your set of tests.
  • baseUrl: The base url that will be used to run the tests.

As an example, here is the cypress.json file of AdmissionChance-Answer at the time of writing this documentation:

{
  "fixturesFolder": false,
  "integrationFolder": "./node_modules/@studyportals/bestfit-test/Tests/AdmissionChanceAnswer",
  "pluginsFile": false,
  "screenshotsFolder": false,
  "supportFile": false,
  "baseUrl": "https://525.mastersportal.fyi/",
  "env":{
    "username": "ETeOGtt",
    "password": "y3J6LW3"
  },
  "defaultCommandTimeout": 15000
}

As you can see, credentials for a pull request environment can also be included under the username and password properties of the env object.

Running tests inside pull requests using Travis

For each of the BestFit front-end microservices, when a pull request is open, new commits trigger Travis to run the end-to-end tests for the respective repository, once the build and staging steps have completed for the pull request environment in AWS.

For a freshly opened pull request, if no manual action is taken, the runs in Travis will break. The manual action(s) that are required, if you want to have your changes automatically tested, are dependant on the microservice:

For questionnaire microservices (AdmissionChance and BestFit-Budget) tests can run stand-alone, without the context of Mastersportal. So, all you need to do is:

  • Change the baseUrl in the configuration of the cypress.json file at the root of the project to the url of the pull request environment, e.g. https://210-ac.prtl.fyi/ and commit this change.

For AdmissionChance-Answer tests can only run in the context of Mastersportal. So, a couple more steps are needed:

  • Copy the contents of the pull request environment, e.g. https://323-aca.prtl.fyi.
  • In the QuickGlance.php file of the Portal repository, make the following change:
// Change this:
return "https://admissionchance-answer.{$env}.prtl.co/";
// To the pull request environment link you copied:
return "https://323-aca.prtl.fyi";
  • Commit this change to a new branch.
  • Open a pull request and add the label Masters to initiate a pull request environment to be opened.
  • Take note of the url and credentials of the pull request environment.
  • In the cypress.json file at the root of AdmissionChance-Answer, set the baseUrl, the env.username and the env.password to the url and credentials of the pull request environment and commit this change.

Now, with every commit, the end-to-end tests should be running on the Mastersportal pull request environment that you opened, which fetches the AdmissionChance-Answer pull request environment instead of the TST microservice.

How the tests are structured

Inside the Tests repository, you can find the following repositories, which are all related to repositories in GitHub:

  • AdmissionChanceAnswer: Tests that verify the entire flow of not only the AdmissionChance-Answer microservice itself (which also makes use of both other microservices), but the study page on Mastersportal, which loads in all three microservices.
  • AdmissionChance: Tests that verify the flow inside the academic questionnaire only.
  • BestFitBudget: Tests that verify the flow inside the budget questionnaire only.

AdmissionChance-Answer tests

The main AdmissionChance-Answer test is, by far, the longest, because the whole flow in all its details is tested. The following list was used to verify that all flow parts are included in the test:

  • Opening academic questionnaire from tabs
  • Opening budget questionnaire from tabs
  • Opening BestFit from main incentive
  • Closing questionnaire without answering any questions
  • Answering all questions (both academic and budget), which includes:
    • Providing the answer itself
    • Validation of the input (when applicable)
    • Verifying that the answer is prefilled when coming back
    • Verifying the right dropdown groups are shown
    • Verifying prefilling for dropdowns that should have nothing-selected-click-away-prefill behaviour (grade & institution questions)
  • Checking details, which includes:
    • Opening and closing accordions
    • Checking tip messages
    • Checking overall fit messages
  • Creating an account
  • Saving answers to an account without conflict
  • Saving answers to an account with conflict
  • Editing an answer from the details

How to write a test

All test code should end up in the Tests/flows folder, and should be used in any of the other repositories to test a part of the flow. All tests are written in JavaScript and can contain code like:

describe('Standard Visit', function(){

	it('Opens BestFit and goes through the Academic questionnaire.', function(){

		cy.visit('https://www.mastersportal.com/studies/622/economics-for-development.html');

		cy.contains('Check your fit with this programme').click().then(() => {

			cy.get('.IntroIncentiveButton:first').click();
		});
	});
});

It is possible to use selectors to find forms and textboxes. The test can run as quickly as the page renders.

Learning more about the API

Check the Introduction to Cypress.

FAQs

Package last updated on 08 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc