Skip to content

Commit

Permalink
test: set default jest_test = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
heystone999 committed Mar 19, 2024
1 parent 61a957e commit 2be4c24
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions memo-backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const middleware = require('./utils/middleware')
const mongoose = require('mongoose')

// set this to 1 if running a jest test
const jest_test = 1

const jest_test = 0
if (jest_test) {
mongoose.connect("mongodb+srv://stone:[email protected]/testMemo?retryWrites=true&w=majority");
} else {
Expand All @@ -30,9 +29,9 @@ app.use(express.json())
// app.use(express.static('build'))
app.use(express.static(path.join(__dirname, 'build')));

app.get('/', function(req, res) {
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
});

app.use('/api/users', usersRouter)
app.use('/api/login', loginRouter)
Expand Down

2 comments on commit 2be4c24

@heystone999
Copy link
Owner Author

Choose a reason for hiding this comment

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

Coverage report for backend

Caution

Test run failed

St.❔
Category Percentage Covered / Total
πŸ”΄ Statements 49.25% 98/199
πŸ”΄ Branches 28.57% 18/63
πŸ”΄ Functions 22.22% 4/18
πŸ”΄ Lines 49.25% 98/199

Test suite run failed

Failed tests: 2/7. Failed suites: 2/3.
  ● POST /api/habits β€Ί should add a new habit

    expected 200 "OK", got 401 "Unauthorized"

      30 |     .post('/api/login')
      31 |     .send({ username: username, password: password })
    > 32 |     .expect(200);
         |      ^
      33 |
      34 |   // Extract the token from the response body
      35 |   token = res.body.token;

      at Object.expect (tests/habits.test.js:32:6)
      ----
      at Test._assertStatus (node_modules/supertest/lib/test.js:252:14)
      at assertFn (node_modules/supertest/lib/test.js:308:13)
      at Test.fn [as _assertFunction] (node_modules/supertest/lib/test.js:285:13)
      at Test._assertFunction [as assert] (node_modules/supertest/lib/test.js:164:23)
      at Server.assert (node_modules/supertest/lib/test.js:120:14)


  ● Login endpoint β€Ί Login with correct credentials should return a token

    expected 200 "OK", got 401 "Unauthorized"

      23 |       .post('/api/login')
      24 |       .send({ username: 'testuser', password: 'password' })
    > 25 |       .expect(200)
         |        ^
      26 |       .expect('Content-Type', /application\/json/);
      27 |
      28 |     expect(response.body.token).toBeDefined();

      at Object.expect (tests/login.test.js:25:8)
      ----
      at Test._assertStatus (node_modules/supertest/lib/test.js:252:14)
      at assertFn (node_modules/supertest/lib/test.js:308:13)
      at Test.fn [as _assertFunction] (node_modules/supertest/lib/test.js:285:13)
      at Test._assertFunction [as assert] (node_modules/supertest/lib/test.js:164:23)
      at Server.assert (node_modules/supertest/lib/test.js:120:14)

Report generated by πŸ§ͺjest coverage report action from 2be4c24

@heystone999
Copy link
Owner Author

Choose a reason for hiding this comment

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

Coverage report for fronend

Caution

Test run failed

St.❔
Category Percentage Covered / Total
πŸ”΄ Statements 34.14% 269/788
πŸ”΄ Branches 22.87% 75/328
πŸ”΄ Functions 24.42% 53/217
πŸ”΄ Lines 34.53% 259/750

Test suite run failed

Failed tests: 1/13. Failed suites: 1/4.
  ● health and level integration test

    TestingLibraryElementError: Unable to find an element with the text: -. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

    Ignored nodes: comments, script, style
    <body>
      <div>
        <div>
          <div>
            <nav>
              <div
                class="nav-left"
              >
                <a
                  class="logo"
                  href="/"
                >
                  MEMO MINDER
                </a>
                <a
                  class=""
                  href="/"
                >
                  <span>
                    Tasks
                  </span>
                </a>
                <a
                  class=""
                  href="/"
                >
                  <span>
                    Shops
                  </span>
                </a>
                <a
                  class=""
                  href="/"
                >
                  <span>
                    Challenges
                  </span>
                </a>
                <a
                  class=""
                  href="/"
                >
                  <span>
                    Milestones
                  </span>
                </a>
              </div>
              <div
                class="nav-middle"
              />
              <div
                class="nav-right"
              >
                <div
                  class="coin"
                >
                  <img
                    alt=""
                    class="coin-icon"
                    src="/coin.png"
                  />
                  <div
                    class="coin-number"
                  >
                    0
                  </div>
                </div>
                <div
                  class="user"
                >
                  <img
                    alt=""
                    class="user-pic"
                    src="/user-pic.png"
                  />
                  <span
                    class="user-name"
                  >
                    Ray
                  </span>
                </div>
              </div>
              <div
                class="user-menu inactive"
              >
                <ul>
                  <li
                    class="user-menu-item"
                  >
                    <a
                      class="logout-link"
                      href="/login"
                    >
                       
                      Log Out
                       
                    </a>
                  </li>
                </ul>
              </div>
            </nav>
            <div
              style="display: flex; flex-direction: column;"
            >
              <div
                class="header"
              >
                <div
                  class="user"
                >
                  <div
                    class="user-character"
                  >
                    <img
                      alt=""
                      class="user-character-pic"
                      src="/char-pic.png"
                    />
                  </div>
                  <div
                    class="user-character-info"
                  >
                    <div
                      class="username"
                    >
                      Ray
                    </div>
                    <div
                      class="user-data"
                    >
                      <div
                        class="health"
                      >
                        <img
                          alt=""
                          src="/heart.png"
                        />
                        <div
                          class="health-bar"
                        >
                          <div
                            class="health-level"
                            style="width: 100%;"
                          />
                        </div>
                        <span>
                          100
                          /100
                        </span>
                      </div>
                      <div
                        class="level"
                      >
                        <img
                          alt=""
                          src="/star.png"
                        />
                        <div
                          class="level-bar"
                        >
                          <div
                            class="level-level"
                            style="width: 0%;"
                          />
                        </div>
                        <span>
                          Level 
                          1
                          : 
                          0
                          /100
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <div
                  class="bag"
                >
                  <div
                    class="bag-name"
                  >
                    Bag
                  </div>
                  <div
                    class="bought-items-images"
                  />
                </div>
              </div>
              <div>
                <div
                  class="taskAreaContainer"
                >
                  <div
                    class="controlButton"
                  >
                    <div
                      class="clearButtonContainer"
                    >
                      <button
                        class="clearButton"
                      >
                        Clear and Reset
                      </button>
                    </div>
                    <div
                      class="task-button-container"
                    >
                      <div
                        class="add-task-button-container"
                      >
                        <button
                          class="add-task-button"
                        >
                          Add Task
                        </button>
                      </div>
                    </div>
                  </div>
                  <div
                    class="taskAreaSections"
                  >
                    <div
                      class="taskAreaSection"
                    >
                      <h2>
                        Habits
                      </h2>
                      <div
                        class="taskAreaNav"
                      >
                        <button>
                          All
                        </button>
                        <button>
                          Good
                        </button>
                        <button>
                          Bad
                        </button>
                      </div>
                      <div
                        class="contentContainer"
                      >
                        <div
                          class="habitInputContainer"
                        >
                          <input
                            class="habitInput"
                            placeholder="Add a habit"
                            type="text"
                            value=""
                          />
                        </div>
                        <div
                          class="taskList"
                        />
                      </div>
                    </div>
                    <div
                      class="taskAreaSection"
                    >
                      <h2>
                        Dailies
                      </h2>
                      <div
                        class="taskAreaNav"
                      >
                        <button>
                          All
                        </button>
                        <button>
                          Due
                        </button>
                        <button>
                          Completed
                        </button>
                      </div>
                      <div
                        class="contentContainer"
                      >
                        <div
                          class="dailyInputContainer"
                        >
                          <input
                            class="dailyInput"
                            placeholder="Add a daily"
                            type="text"
                            value=""
                          />
                        </div>
                        <div
                          class="taskList"
                        >
                          <div
                            class="dailyItem "
                          >
                            <button>
                              +
                            </button>
                            <p>
                              Your default daily
                            </p>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div
                      class="taskAreaSection"
                    >
                      <h2>
                        To Do Lists
                      </h2>
                      <div
                        class="taskAreaNav"
                      >
                        <button>
                          All
                        </button>
                        <button>
                          Scheduled
                        </button>
                        <button>
                          Completed
                        </button>
                      </div>
                      <div
                        class="contentContainer"
                      >
                        <div
                          class="todoInputContainer"
                        >
                          <input
                            class="todoInput"
                            placeholder="Add a To Do"
                            type="text"
                            value=""
                          />
                        </div>
                        <div
                          class="taskList"
                        >
                          <div
                            class="todoItem "
                          >
                            <button>
                              +
                            </button>
                            <p>
                              Your default to-do
                            </p>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div
                      class="taskAreaSection"
                    >
                      <h2>
                        Rewards
                      </h2>
                      <div
                        class="taskAreaNav"
                      >
                        <button>
                          All
                        </button>
                      </div>
                      <div
                        class="contentContainer"
                      >
                        <div
                          class="rewardInputContainer"
                        >
                          <input
                            class="rewardInput"
                            placeholder="Add a Reward"
                            type="text"
                            value=""
                          />
                        </div>
                        <div
                          class="taskList"
                        >
                          <div
                            class="rewardItem"
                          >
                            <button>
                              10
                               coins
                            </button>
                            <p>
                              Your default reward
                            </p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </body>

      12 |
      13 |     // Trigger a negative habit click
    > 14 |     fireEvent.click(screen.getByText('-'));
         |                            ^
      15 |
      16 |     // Health should decrease by 10
      17 |     expect(screen.getByText('90/100')).toBeInTheDocument();

      at Object.getElementError (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/config.js:37:19)
      at node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:76:38
      at node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:52:17
      at getByText (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/query-helpers.js:95:19)
      at Object.<anonymous> (src/tests/AppIntegration.test.js:14:28)

Report generated by πŸ§ͺjest coverage report action from 2be4c24

Please sign in to comment.