mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 20:45:00 +02:00
QFIX: Check last visit in gmail service (#9300)
* QFIX: Check last visit in gmail service Signed-off-by: Andrey Sobolev <haiodo@gmail.com> * QFix: Fix workspace loop and tests Signed-off-by: Artem Savchenko <armisav@gmail.com> * QFix: check pending workspaces in background Signed-off-by: Artem Savchenko <armisav@gmail.com> * QFix: Handle errors in checkPendingWorkspaces Signed-off-by: Artem Savchenko <armisav@gmail.com> --------- Signed-off-by: Andrey Sobolev <haiodo@gmail.com> Signed-off-by: Artem Savchenko <armisav@gmail.com> Co-authored-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
co-authored by
Artem Savchenko
parent
c74ce51be8
commit
3fc81cdbdb
@@ -43,10 +43,12 @@ describe('GmailController', () => {
|
||||
|
||||
const workspaceAId: WorkspaceUuid = 'workspace-a' as any
|
||||
const workspaceBId: WorkspaceUuid = 'workspace-b' as any
|
||||
const inactiveWorkspaceId: WorkspaceUuid = 'inactive-workspace' as any
|
||||
const outdatedWorkspaceId: WorkspaceUuid = 'outdated-workspace' as any
|
||||
|
||||
const workspaceATokens: Token[] = [
|
||||
{ userId: 'user1', workspace: workspaceAId, token: 'token1' } as any,
|
||||
{ userId: 'user2', workspace: workspaceAId, token: 'token2' } as any
|
||||
{ uuid: workspaceAId, userId: 'user1', workspace: workspaceAId, token: 'token1' } as any,
|
||||
{ uuid: workspaceBId, userId: 'user2', workspace: workspaceAId, token: 'token2' } as any
|
||||
]
|
||||
|
||||
const workspaceBTokens: Token[] = [
|
||||
@@ -55,6 +57,18 @@ describe('GmailController', () => {
|
||||
{ userId: 'user5', workspace: workspaceBId, token: 'token5' } as any
|
||||
]
|
||||
|
||||
const inactiveWorkspaceTokens: Token[] = [
|
||||
{ userId: 'user3', workspace: workspaceBId, token: 'token6' } as any,
|
||||
{ userId: 'user4', workspace: workspaceBId, token: 'token7' } as any,
|
||||
{ userId: 'user5', workspace: workspaceBId, token: 'token8' } as any
|
||||
]
|
||||
|
||||
const outdatedWorkspaceTokens: Token[] = [
|
||||
{ userId: 'user3', workspace: workspaceBId, token: 'token6' } as any,
|
||||
{ userId: 'user4', workspace: workspaceBId, token: 'token7' } as any,
|
||||
{ userId: 'user5', workspace: workspaceBId, token: 'token8' } as any
|
||||
]
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
@@ -82,7 +96,12 @@ describe('GmailController', () => {
|
||||
// Create mock clients with unique properties
|
||||
mockGmailClients = new Map()
|
||||
|
||||
const allUsers = [...workspaceATokens, ...workspaceBTokens].map((token) => token.userId)
|
||||
const allUsers = [
|
||||
...workspaceATokens,
|
||||
...workspaceBTokens,
|
||||
...inactiveWorkspaceTokens,
|
||||
...outdatedWorkspaceTokens
|
||||
].map((token) => token.userId)
|
||||
allUsers.forEach((userId) => {
|
||||
mockGmailClients.set(userId, {
|
||||
startSync: jest.fn().mockResolvedValue(undefined),
|
||||
@@ -108,14 +127,40 @@ describe('GmailController', () => {
|
||||
|
||||
// Mock getWorkspaceTokens
|
||||
jest.spyOn(tokens, 'getWorkspaceTokens').mockImplementation(async (_, workspaceId) => {
|
||||
if (workspaceId === workspaceAId) return workspaceATokens
|
||||
if (workspaceId === workspaceBId) return workspaceBTokens
|
||||
return []
|
||||
const result = new Map<WorkspaceUuid, Token[]>()
|
||||
if (workspaceId === workspaceAId || workspaceId === undefined) result.set(workspaceAId, workspaceATokens)
|
||||
if (workspaceId === workspaceBId || workspaceId === undefined) result.set(workspaceBId, workspaceBTokens)
|
||||
if (workspaceId === inactiveWorkspaceId || workspaceId === undefined) {
|
||||
result.set(inactiveWorkspaceId, inactiveWorkspaceTokens)
|
||||
}
|
||||
if (workspaceId === outdatedWorkspaceId || workspaceId === undefined) {
|
||||
result.set(outdatedWorkspaceId, outdatedWorkspaceTokens)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
// Mock getAccountClient
|
||||
jest.spyOn(serverClient, 'getAccountClient').mockReturnValue({
|
||||
getWorkspaceInfo: jest.fn().mockResolvedValue({ mode: 'active' })
|
||||
getWorkspaceInfo: jest.fn().mockResolvedValue({ mode: 'active' }),
|
||||
getWorkspacesInfo: jest.fn().mockResolvedValue([
|
||||
{ uuid: workspaceAId, workspaceUuid: workspaceAId, name: 'Workspace A', mode: 'active', lastVisit: Date.now() },
|
||||
{ uuid: workspaceBId, workspaceUuid: workspaceBId, name: 'Workspace B', mode: 'active', lastVisit: Date.now() },
|
||||
{
|
||||
uuid: inactiveWorkspaceId,
|
||||
workspaceUuid: inactiveWorkspaceId,
|
||||
name: 'Inactive Workspace',
|
||||
mode: 'archived',
|
||||
lastVisit: Date.now()
|
||||
},
|
||||
{
|
||||
uuid: outdatedWorkspaceId,
|
||||
workspaceUuid: outdatedWorkspaceId,
|
||||
name: 'Outdated Workspace',
|
||||
mode: 'active',
|
||||
lastVisit: Date.now() - 7 * 3600 * 24 * 1000
|
||||
}
|
||||
])
|
||||
} as any)
|
||||
|
||||
// Mock serviceToken
|
||||
|
||||
Reference in New Issue
Block a user