-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/issue 314 #319
Merged
Caleb-Cohen
merged 6 commits into
Together-100Devs:development
from
RascalTwo:feature/issue-314
Feb 11, 2023
Merged
Feature/issue 314 #319
Caleb-Cohen
merged 6 commits into
Together-100Devs:development
from
RascalTwo:feature/issue-314
Feb 11, 2023
Conversation
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
Update eslint config Update gitignore Add testing development mongo path
Cypress wasn't properly listening to the CYPRESS_NO_DELAYS environment variable to disable the animations waits
This dude is cracked I swear |
Just Rascal being Rascal. |
Caleb-Cohen
added a commit
that referenced
this pull request
Feb 18, 2023
* Added testing to pull request template * Feature/issue 314 (#319) * Install Cypress & needed packages Update eslint config Update gitignore Add testing development mongo path * Add nock Passport.js Discord request interception * Add Cypress tests * Disable server logging when testing * Fix delay-toggling environment variable Cypress wasn't properly listening to the CYPRESS_NO_DELAYS environment variable to disable the animations waits * added modulus to getHoursAndMinutes --------- Co-authored-by: Caleb Cohen <CalebCohen@hotmail.com> * starting workflow for actions * typo within review pull request * add environment dev to workflow * workflow changes * lint fixes (#324) * Actions timeout (#326) * Add timeout to GitHub actions GitHub action workflows should be limited so minutes aren't wasted if it hangs and bugs can be caught earlier. If 30 minutes isn't enough, it can be increased later on * change timeout to 10 minutes * Modified app metadata to "Together is a scheduling and collaboration … (#325) * Modified app metadata to "Together is a scheduling and collaboration tool built for and by 100Devs community for creating, discovering and keeping track of events on discord." * Deleted the extra space. * Server tests. #288 (#289) * install jest and supertest * separate app and server into different files * add jest coverage folder to gitignore * allow the use of mock user in test environment * change validateBody to be a sync function * add 'use strict', fix variable declarations * extract constants * remove console logs * add mock user to db * refactor, fix validation bugs in createEventSchema * test httpError * test validateObjectId * test validateBody * refactor unit tests * export STRING_MAX_LENGTH to be used in tests * fix dotenv path to work in tests * modify mock request * test routes * refactor maxEvents middleware * add tests for maxEvents * allow event end time (not date) to be before start time * test create event with valid data * timezone bug fix: add offset to days * test createEventArray * create date range with Date instead of datefns lib * test createEventsArray in JST timezone * refactor createEventsArray and tests * fix test JST time * use Temporal to work with dates * fix event duration using Temporal * test cases for createEventsArray * test validateBody * fix acceptance tests * change hardcoded timezone to machine timezone * update test script * remove irrelevant test (maxEvents) * update front-end test * add script to run all tests together * add route tests * added formidable, jsbi, moved jest and supertest to dev dependencies --------- Co-authored-by: Caleb Cohen <CalebCohen@hotmail.com> * Fix guest modal and and updated test (#327) * Fix guest modal and and updated test * author changes and lint fix * Make time-asserting code locale-based --------- Co-authored-by: Rascal_Two <therealrascaltwo@gmail.com> * Removed delete all button from non-recurring events (#332) * Removed delete all button from non-recurring events * Removed console.log from file * Feature/issue 305 (#339) * changed description section input element to textarea element. This change added multi-line functionality and a larger textbox size. * In the input object, I changed the input element text to textarea. Cypress now reflects the changes made in the codebase for proper testing. * Created a close button, in UserForm.js (#333) --------- Co-authored-by: Rascal Two <therealrascaltwo@gmail.com> Co-authored-by: Jacob Asper <jacobasper191@gmail.com> Co-authored-by: uaravindshenoy <75222342+uaravindshenoy@users.noreply.github.com> Co-authored-by: Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> Co-authored-by: Lalysi <75863568+lalysi@users.noreply.github.com> Co-authored-by: Mike Jakuszewski <114702999+MikeJakuszewski@users.noreply.github.com> Co-authored-by: Jae Salaski <hello@jsalaski.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implements front-end End-to-End testing using Cypress with code coverage results, additionally intercepting the Discord OAuth2 requests using
nock
to allow for testing of the entire login flow.This is quite a large PR, but it contains mostly the new test files with a few additions to the express server and of course new
package.json
script
s.The new packages are:
@cypress/code-coverage
@cypress/instrument-cra
@cypress/code-coverage
.cross-env
package.json
scripts, which needed to set the server to run intest
mode.cypress
eslint-plugin-cypress
nock
nyc
start-server-and-test
Newly added scripts include:
/package.json
coverage-concurrent
dev-concurrent
, it starts up both the client and server in coverage mode - collecting code coverage results.wait-for-coverage-concurrent
coverage-concurrent
but viastart-server-and-test
, ensuring Cypress isn't opened until the servers are ready.test-frontend
dev-frontend-tests
/server/package.json
start:coverage
nyc
, collecting code coverage results./client/package.json
start:coverage
@cypress/instrument-cra
to instrument the code for code coverage collection.There exists only one additional environment variable:
CYPRESS_NO_DELAYS
The changes to the backend are mostly to allow for the mocking of the Discord OAuth2 requests, these have been encapsulated in a new file
passport-discord-mocking.js
, containing both the usage ofnock
to mock intercept the requests and the responses for each request endpoints.Additional backend changes include the disabling of logging - both
console.log()
s and usage ofmorgan
- when running the tests. This was done by using the standardNODE_ENV
variable, and only enabling logging whenNODE_ENV
is nottest
.It can be difficult to understand what the mocking has changed unless one knows how it was working before, so here is a diagram of the original flow between the frontend client, our Express server with Passport.js, and lastly the Discord API:
The most important part of this is that the difference implemented when the server is running in
test
mode is that instead of making requests to the real Discord API, the Passport.js requests will instead be intercepted bynock
and mocked with the appropriate response - based on the hardcoded user codes.Additionally, Cypress has one role to play in the testing, and that is to intercept the request made to the
/auth/discord
endpoint that would usually redirect the user to the Discord OAuth2 page, and instead redirect the user back to the Express server with a custom code that will be exchanged for the preset responses.Now to move on to the actual new Cypress files:
cypress.config.js
clearDatabase
createEvent
generateObjectId
cypress
videos
&screenshots
support
e2e.js
beforeEach
hook to reset the database before each test and visit the homepage.functions.js
commands.js
login
createOwnEvents
tgt.js
e2e
auth.cy.js
landing.cy.js
calendar.cy.js
view-event-modal.cy.js
create-event-form.cy.js
I did discover a number of unused code segments while writing the tests, while some may have future use I'll list them just in case:
/events/:id
route, linkedgetOne
controller, andgetById
DataService
methodensureGuest
middlewareavatarURL
virtualuseProvideModel()
handleToggle
functionuseProvideFormModel()
handleToggle
functionAdditionally, I ran across two bugs while writing the tests:
Delete All Events
button, which currently only throws an error.Delete Specific Event
button - I left nothing in the tests relating to it.groupId
ofnull
, hence the button results in aDELETE
request to/events/deleteAllEvents/null
.Type of change
Please select everything applicable. Please, do not delete any lines.
package.json
scriptstest-frontend
anddev-frontend-tests
Issue
Checklist
npm run lint
and resolved any outstanding errors. Most issues can be solved by executingnpm run format