Skip to content
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

Server tests. #288 #289

Merged
merged 45 commits into from
Feb 17, 2023
Merged

Conversation

romanstetsyk
Copy link
Contributor

@romanstetsyk romanstetsyk commented Jan 25, 2023

Description

Added Jest tests for Express middleware:
To run tests: npm run test

Type of change

Please select everything applicable. Please, do not delete any lines.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Issue

Checklist:

  • This PR is up to date with the development branch, and merge conflicts have been resolved
  • I have executed npm run lint and resolved any outstanding errors. Most issues can be solved by executing npm run format
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

@@ -0,0 +1,82 @@
const express = require("express");
const path = require("path");
const app = express();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express app and server needed to be separated into separate files so that app could be imported into the tests without starting the server

description: "starts and ends on the same UTC day",
input: {
...commonFormFields,
firstEventStart: Date.parse("2023-01-28T15:00:00.000+00:00"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I received typeerrors in all the tests in this sequence when I tried to run it! It looks like we're trying to feed the createEventsArray function an object with the properties "firstEventStart", "firstEventEnd", and "lastEventStart" when it's expecting to receive "initialDate", "finalDate", "startTime", and "endTime".

@@ -10,8 +10,8 @@ const { createEventSchema } = require("../models/Event");
router.post(
"/",
auth.ensureAuth,
validateBody(createEventSchema),
maxEvents,
// validateBody(createEventSchema),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like when I uncomment these, creating an event returns a 400 error.

if (endDateTime < startDateTime) {
errorArray.push("Error: End time is before Start time");
}
// if (endDateTime < startDateTime) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to remain commented out?

Copy link
Collaborator

@MatthewBozin MatthewBozin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Roman!
I tried out the test suite! All test files worked fine except for createEventsArray (left a comment regarding the likely cause). While the app works fine, I noticed you've commented out a few of the form validation checks on the client and server side and wanted to know more about that before we merge this PR.
Thanks!
-Matt

@romanstetsyk
Copy link
Contributor Author

@MatthewBozin thank you for reviewing this PR. This is a work in progress. It was made before we discovered bugs dealing with time zones and daylight-saving time. I am considering different approaches to solving this, and the tests haven't been updated yet.

@MatthewBozin
Copy link
Collaborator

Ah gotcha! Thanks for letting me know!

@romanstetsyk
Copy link
Contributor Author

@MatthewBozin I've fixed the timezone bug (hopefully). Could you review the updated PR? We might need to add a warning when someone tries to create an event when time switches from normal to daylight-saving, as the display times may be misleading. But the most important thing is that in the database, the UTC times are saved correctly!

@romanstetsyk romanstetsyk temporarily deployed to DEV February 13, 2023 16:08 — with GitHub Actions Inactive
@romanstetsyk romanstetsyk temporarily deployed to DEV February 14, 2023 02:17 — with GitHub Actions Inactive
@romanstetsyk romanstetsyk temporarily deployed to DEV February 14, 2023 20:32 — with GitHub Actions Inactive
@Caleb-Cohen Caleb-Cohen temporarily deployed to DEV February 15, 2023 23:05 — with GitHub Actions Inactive
@Caleb-Cohen
Copy link
Member

Added a commit please review.

@Caleb-Cohen Caleb-Cohen merged commit 28e3b03 into Together-100Devs:development Feb 17, 2023
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants