bundle install
to install the gem dependenciesyarn
to install node dependenciesrails db:prepare
to setup the databaseaz login
and then make local setup-local-env
to populate development secrets./bin/dev
to run the rails server, shakapacker-dev-server, redis and sidekiq.GIT_API_ENDPOINT=https://localhost:5001/api \
GIT_API_TOKEN=secret-git \
bundle exec rails server
You need to have the correct version of chromedriver
installed for the version of Chrome you are running.
rspec
yarn spec
We have a number of integration tests that will run on a deployment to production; these are exectured on our hosted test environment and perform end-to-end tests of the mailing list, event and adviser sign up journeys.
As we test the TOTP authentication mechanism as part of the integration tests we make use of mailsac as our test inbox for receiving the TOTP. The API key is part of the infra secrets and can be viewed/changed with make test <print|edit>-infra-secrets
.
The adviser sign up journey has a number of contract tests. These work similar to snapshot testing in Jest; a sign up is performed via Capybara and the payload that would be sent to the API is captured as the ‘contract output’. If a change causes the payload to change the test will fail and you need to remove the previous snapshot (contract output) if the change is expected.
These output files are used as inputs into the API contract tests; we feed in the snapshot and capture the requests the API makes to the CRM, performing the same process). At the moment updating the input snapshots in the API is performed manually when something changes; ideally this would be automated in CI in the future.
We have various linters in place to enforce code consistency; these will be ran automatically as part of CI, but you can run them locally/configure a pre-commit hook if you prefer.
Lint Ruby with rubocop
(autofix with rubocop -A
).
Prettier is used for code formatting. ESLint is used for static analysis of JavaScript code quality. It is configured to ignore stylistic rules that conflict with Prettier, and uses the JavaScript Standard style.
To list any violations in the project’s JavaScript:
yarn js-lint
To automatically fix any violations. Any violations that cannot be automatically fixed will be listed in the output (note: this will overwrite any file that needs formatting):
yarn js-lint-fix
StyleLint is used for CSS linting, it uses the GDS Stylelint Config.
To lint the ./app/webpacker/styles
directory:
# Run StyleLint
yarn scss-lint
# Automatically fix, where possible, violations reported by rules
yarn scss-lint --fix
There are a couple of aspects to be aware of when developing on the Get into Teaching website:
HtmlResponseTransformer
middleware does various sweeping changes to responses, primarily for image optimisation but also accessibility, errors and links. Its worth making yourself familiar with the middelware.rails dev:cache
. It is applied via the PagesController
by default to content. There is also custom middleware to prevent any pages rendering a form from being cached (as the CSRF token would become invalid). The cache is cleared on deployment and the cached pages have a 5 minute TTL.png
image and it will be compressed, converted and presented automatically (via the HtmlResponseTransformer
middleware).git_wizard
gem; its currently only used by the Get into Teaching website and Get an adviser service so it can be changed freely/without worry of effecting other teams. Soon only the Get into Teaching website will use this gem so we may want to bring it into the codebase for ease of maintenance.