2023-06-29 18:26:45 +02:00
|
|
|
import o from "@tutao/otest"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { Notifications } from "../../../src/gui/Notifications.js"
|
|
|
|
import type { Spy } from "@tutao/tutanota-test-utils"
|
|
|
|
import { spy } from "@tutao/tutanota-test-utils"
|
|
|
|
import type { MailboxDetail } from "../../../src/mail/model/MailModel.js"
|
|
|
|
import { MailModel } from "../../../src/mail/model/MailModel.js"
|
|
|
|
import { MailFolderType, OperationType } from "../../../src/api/common/TutanotaConstants.js"
|
2023-11-10 16:59:39 +01:00
|
|
|
import { MailFolderTypeRef, MailTypeRef } from "../../../src/api/entities/tutanota/TypeRefs.js"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { EntityClient } from "../../../src/api/common/EntityClient.js"
|
|
|
|
import { EntityRestClientMock } from "../api/worker/rest/EntityRestClientMock.js"
|
2022-05-12 16:51:15 +02:00
|
|
|
import nodemocker from "../nodemocker.js"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { downcast } from "@tutao/tutanota-utils"
|
2023-02-10 16:27:53 +01:00
|
|
|
import { MailFacade } from "../../../src/api/worker/facades/lazy/MailFacade.js"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { LoginController } from "../../../src/api/main/LoginController.js"
|
2023-08-31 16:31:00 +02:00
|
|
|
import { matchers, object, when } from "testdouble"
|
2023-01-12 14:54:42 +01:00
|
|
|
import { FolderSystem } from "../../../src/api/common/mail/FolderSystem.js"
|
2022-12-28 15:28:28 +01:00
|
|
|
import { WebsocketConnectivityModel } from "../../../src/misc/WebsocketConnectivityModel.js"
|
2023-05-17 16:49:56 +02:00
|
|
|
import { InboxRuleHandler } from "../../../src/mail/model/InboxRuleHandler.js"
|
2023-08-31 16:31:00 +02:00
|
|
|
import { UserController } from "../../../src/api/main/UserController.js"
|
2023-11-10 16:59:39 +01:00
|
|
|
import { createTestEntity } from "../TestUtils.js"
|
2024-01-08 17:14:09 +01:00
|
|
|
import { EntityUpdateData } from "../../../src/api/common/utils/EntityUpdateUtils.js"
|
2018-10-22 12:02:13 +02:00
|
|
|
|
|
|
|
o.spec("MailModelTest", function () {
|
2021-12-23 14:03:23 +01:00
|
|
|
let notifications: Partial<Notifications>
|
2018-10-22 12:02:13 +02:00
|
|
|
let showSpy: Spy
|
|
|
|
let model: MailModel
|
2023-11-10 16:59:39 +01:00
|
|
|
const inboxFolder = createTestEntity(MailFolderTypeRef, { _id: ["folderListId", "inboxId"] })
|
2018-10-22 12:02:13 +02:00
|
|
|
inboxFolder.mails = "instanceListId"
|
|
|
|
inboxFolder.folderType = MailFolderType.INBOX
|
2023-11-10 16:59:39 +01:00
|
|
|
const anotherFolder = createTestEntity(MailFolderTypeRef, { _id: ["folderListId", "archiveId"] })
|
2018-10-22 12:02:13 +02:00
|
|
|
anotherFolder.mails = "anotherListId"
|
|
|
|
anotherFolder.folderType = MailFolderType.ARCHIVE
|
2022-12-19 16:38:14 +01:00
|
|
|
let mailboxDetails: Partial<MailboxDetail>[]
|
2022-11-08 17:06:42 +01:00
|
|
|
let logins: LoginController
|
2023-05-17 16:49:56 +02:00
|
|
|
let inboxRuleHandler: InboxRuleHandler
|
|
|
|
|
2018-10-22 12:02:13 +02:00
|
|
|
o.beforeEach(function () {
|
2022-12-19 16:38:14 +01:00
|
|
|
mailboxDetails = [
|
|
|
|
{
|
|
|
|
folders: new FolderSystem([inboxFolder]),
|
|
|
|
},
|
|
|
|
]
|
2018-10-22 12:02:13 +02:00
|
|
|
notifications = {}
|
|
|
|
showSpy = notifications.showNotification = spy()
|
2021-09-24 13:26:42 +02:00
|
|
|
const restClient = new EntityRestClientMock()
|
2022-12-28 15:28:28 +01:00
|
|
|
const connectivityModel = object<WebsocketConnectivityModel>()
|
2022-01-07 15:58:30 +01:00
|
|
|
const mailFacade = nodemocker.mock<MailFacade>("mailFacade", {}).set()
|
2022-11-08 17:06:42 +01:00
|
|
|
logins = object()
|
2023-08-31 16:31:00 +02:00
|
|
|
let userController = object<UserController>()
|
|
|
|
when(userController.isUpdateForLoggedInUserInstance(matchers.anything(), matchers.anything())).thenReturn(false)
|
|
|
|
when(logins.getUserController()).thenReturn(userController)
|
|
|
|
|
2023-05-17 16:49:56 +02:00
|
|
|
inboxRuleHandler = object()
|
|
|
|
model = new MailModel(downcast(notifications), downcast({}), connectivityModel, mailFacade, new EntityClient(restClient), logins, inboxRuleHandler)
|
2018-10-22 12:02:13 +02:00
|
|
|
// not pretty, but works
|
2022-01-07 15:58:30 +01:00
|
|
|
model.mailboxDetails(mailboxDetails as MailboxDetail[])
|
2018-10-22 12:02:13 +02:00
|
|
|
})
|
2020-09-16 14:36:28 +02:00
|
|
|
o("doesn't send notification for another folder", async function () {
|
2023-08-31 16:31:00 +02:00
|
|
|
await model.entityEventsReceived(
|
|
|
|
[
|
|
|
|
makeUpdate({
|
|
|
|
instanceListId: anotherFolder.mails,
|
|
|
|
operation: OperationType.CREATE,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
"userGroupId",
|
|
|
|
)
|
2018-10-22 12:02:13 +02:00
|
|
|
o(showSpy.invocations.length).equals(0)
|
|
|
|
})
|
2020-09-16 14:36:28 +02:00
|
|
|
o("doesn't send notification for move operation", async function () {
|
2023-08-31 16:31:00 +02:00
|
|
|
await model.entityEventsReceived(
|
|
|
|
[
|
|
|
|
makeUpdate({
|
|
|
|
instanceListId: anotherFolder.mails,
|
|
|
|
operation: OperationType.DELETE,
|
|
|
|
}),
|
|
|
|
makeUpdate({
|
|
|
|
instanceListId: inboxFolder.mails,
|
|
|
|
operation: OperationType.CREATE,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
"userGroupId",
|
|
|
|
)
|
2018-10-22 12:02:13 +02:00
|
|
|
o(showSpy.invocations.length).equals(0)
|
|
|
|
})
|
|
|
|
|
2022-12-27 15:37:40 +01:00
|
|
|
function makeUpdate(arg: { instanceListId: string; operation: OperationType }): EntityUpdateData {
|
2022-01-07 15:58:30 +01:00
|
|
|
return Object.assign(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
type: MailTypeRef.type,
|
|
|
|
application: MailTypeRef.app,
|
|
|
|
instanceId: "instanceId",
|
|
|
|
},
|
|
|
|
arg,
|
|
|
|
)
|
2018-10-22 12:02:13 +02:00
|
|
|
}
|
2022-12-27 15:37:40 +01:00
|
|
|
})
|