Skip to content

Commit

Permalink
Fix: notification tests to work with new behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs authored and seaerchin committed Nov 7, 2022
1 parent 176fe0f commit d001cf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
39 changes: 14 additions & 25 deletions src/integration/Notifications.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import express from "express"
import mockAxios from "jest-mock-axios"
import request from "supertest"

import { NotificationsRouter as _NotificationsRouter } from "@routes/v2/authenticatedSites/notifications"

import {
IsomerAdmin,
Notification,
Repo,
Site,
SiteMember,
User,
} from "@database/models"
import { Notification, Repo, Site, SiteMember, User } from "@database/models"
import { generateRouter } from "@fixtures/app"
import UserSessionData from "@root/classes/UserSessionData"
import {
Expand All @@ -29,19 +21,10 @@ import {
mockSiteName,
} from "@root/fixtures/sessionData"
import { SitesRouter as _SitesRouter } from "@root/routes/v2/authenticated/sites"
import { GitHubService } from "@root/services/db/GitHubService"
import { ConfigYmlService } from "@root/services/fileServices/YmlFileServices/ConfigYmlService"
import IsomerAdminsService from "@root/services/identity/IsomerAdminsService"
import { SitesService } from "@root/services/utilServices/SitesService"
import { getUsersService, notificationsService } from "@services/identity"
import { sequelize } from "@tests/database"
import { notificationsService } from "@services/identity"

const mockSite = "mockSite"
const mockSiteId = "1"
const mockAdminSite = "adminOnly"
const mockUpdatedAt = "now"
const mockPermissions = { push: true }
const mockPrivate = true
const mockSiteMemberId = "1"

const notificationsRouter = new _NotificationsRouter({ notificationsService })
Expand Down Expand Up @@ -130,7 +113,7 @@ describe("Notifications Router", () => {
where: {},
})
})
it("should return sorted list of most recent notifications if there are less than 6 unread", async () => {
it("should return sorted list of most recent notifications if there are no unread", async () => {
// Arrange
await Notification.create({
userId: mockIsomerUserId,
Expand All @@ -154,7 +137,7 @@ describe("Notifications Router", () => {
userId: mockIsomerUserId,
siteId: mockSiteId,
siteMemberId: 1,
...highPriorityUnreadNotification,
...normalPriorityOldReadNotification,
})
await Notification.create({
userId: mockIsomerUserId,
Expand All @@ -166,7 +149,13 @@ describe("Notifications Router", () => {
userId: mockIsomerUserId,
siteId: mockSiteId,
siteMemberId: 1,
...normalPriorityUnreadNotification,
...normalPriorityReadNotification,
})
await Notification.create({
userId: mockIsomerUserId,
siteId: mockSiteId,
siteMemberId: 1,
...normalPriorityReadNotification,
})
await Notification.create({
userId: mockAdditionalUserId,
Expand All @@ -181,10 +170,10 @@ describe("Notifications Router", () => {
...normalPriorityUnreadNotification,
})
const expected = [
highPriorityUnreadNotification,
normalPriorityUnreadNotification,
highPriorityReadNotification,
normalPriorityReadNotification,
normalPriorityReadNotification,
normalPriorityReadNotification,
highPriorityOldReadNotification,
normalPriorityOldReadNotification,
].map((notification) => formatNotification(notification))
Expand All @@ -196,7 +185,7 @@ describe("Notifications Router", () => {
expect(actual.body).toMatchObject(expected)
})

it("should return only unread notifications if there are 6 or more", async () => {
it("should return only unread notifications if there are any", async () => {
// Arrange
await Notification.create({
userId: mockIsomerUserId,
Expand Down
12 changes: 6 additions & 6 deletions src/services/identity/__tests__/NotificationsService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ describe("Notification Service", () => {
// Arrange
const expected = mockNotifications.slice(0, 6)

MockRepository.findAll.mockResolvedValueOnce(
mockNotificationsResponse.slice(0, 3)
)
MockRepository.findAll.mockResolvedValueOnce([])
MockRepository.findAll.mockResolvedValueOnce(
mockNotificationsResponse.slice(0, 6)
)
Expand All @@ -111,10 +109,12 @@ describe("Notification Service", () => {
expect(MockRepository.findAll).toHaveBeenCalledTimes(2)
})

it("should return the result directly if more than 6 new notifications available", async () => {
it("should return the result directly if new notifications available", async () => {
// Arrange
const expected = mockNotifications
MockRepository.findAll.mockResolvedValueOnce(mockNotificationsResponse)
const expected = mockNotifications.slice(0, 2)
MockRepository.findAll.mockResolvedValueOnce(
mockNotificationsResponse.slice(0, 2)
)

// Act
const actual = NotificationsService.listRecent({
Expand Down

0 comments on commit d001cf1

Please sign in to comment.