From d232e71683d553ddaa41dd2f75716cdf8e62a19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Mon, 17 Oct 2022 09:12:12 +0200 Subject: [PATCH] fix(workspaces): add debug logs for listing workspaces --- .github/workflows/workspace.release.yml | 1 - .../UseCase/ListWorkspaces/ListWorkspaces.spec.ts | 7 ++++++- .../UseCase/ListWorkspaces/ListWorkspaces.ts | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workspace.release.yml b/.github/workflows/workspace.release.yml index 0738ee1d9..c346d30d6 100644 --- a/.github/workflows/workspace.release.yml +++ b/.github/workflows/workspace.release.yml @@ -31,7 +31,6 @@ jobs: node-version-file: '.nvmrc' - name: Build - if: steps.cache-build.outputs.cache-hit != 'true' run: yarn build:workspace lint: diff --git a/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.spec.ts b/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.spec.ts index 9f3231845..ea6a42a84 100644 --- a/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.spec.ts +++ b/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.spec.ts @@ -1,5 +1,6 @@ import { WorkspaceAccessLevel } from '@standardnotes/common' import 'reflect-metadata' +import { Logger } from 'winston' import { Workspace } from '../../Workspace/Workspace' import { WorkspaceRepositoryInterface } from '../../Workspace/WorkspaceRepositoryInterface' import { WorkspaceUser } from '../../Workspace/WorkspaceUser' @@ -14,10 +15,14 @@ describe('ListWorkspaces', () => { let joinedWorkspace: Workspace let workspaceUser1: WorkspaceUser let workspaceUser2: WorkspaceUser + let logger: Logger - const createUseCase = () => new ListWorkspaces(workspaceRepository, workspaceUserRepository) + const createUseCase = () => new ListWorkspaces(workspaceRepository, workspaceUserRepository, logger) beforeEach(() => { + logger = {} as jest.Mocked + logger.debug = jest.fn() + ownedWorkspace = { uuid: 'o-1-2-3' } as jest.Mocked joinedWorkspace = { uuid: 'j-1-2-3' } as jest.Mocked diff --git a/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.ts b/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.ts index c5da78581..9895744b1 100644 --- a/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.ts +++ b/packages/workspace/src/Domain/UseCase/ListWorkspaces/ListWorkspaces.ts @@ -1,5 +1,6 @@ import { WorkspaceAccessLevel } from '@standardnotes/common' import { inject, injectable } from 'inversify' +import { Logger } from 'winston' import TYPES from '../../../Bootstrap/Types' import { Workspace } from '../../Workspace/Workspace' @@ -15,9 +16,12 @@ export class ListWorkspaces implements UseCaseInterface { constructor( @inject(TYPES.WorkspaceRepository) private workspaceRepository: WorkspaceRepositoryInterface, @inject(TYPES.WorkspaceUserRepository) private workspaceUserRepository: WorkspaceUserRepositoryInterface, + @inject(TYPES.Logger) private logger: Logger, ) {} async execute(dto: ListWorkspacesDTO): Promise { + this.logger.debug(`Listing workspaces for user ${dto.userUuid}`) + const workspaceAssociations = await this.workspaceUserRepository.findByUserUuid(dto.userUuid) const ownedWorkspacesUuids = [] @@ -30,6 +34,9 @@ export class ListWorkspaces implements UseCaseInterface { } } + this.logger.debug(`Owned workspaces uuids: ${JSON.stringify(ownedWorkspacesUuids)}`) + this.logger.debug(`Joined workspaces uuids: ${JSON.stringify(joinedWorkspacesUuids)}`) + let ownedWorkspaces: Array = [] if (ownedWorkspacesUuids.length > 0) { ownedWorkspaces = await this.workspaceRepository.findByUuids(ownedWorkspacesUuids) @@ -39,6 +46,13 @@ export class ListWorkspaces implements UseCaseInterface { joinedWorkspaces = await this.workspaceRepository.findByUuids(joinedWorkspacesUuids) } + this.logger.debug( + `Found workspaces for user ${dto.userUuid}: ${JSON.stringify({ + ownedWorkspaces, + joinedWorkspaces, + })}`, + ) + return { ownedWorkspaces, joinedWorkspaces,