Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roystbeef committed Jan 25, 2024
1 parent 0216447 commit 04ea253
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/usecases/handle-figma-file-update-event-use-case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import { handleFigmaFileUpdateEventUseCase } from './handle-figma-file-update-event-use-case';

import { FigmaTeamAuthStatus } from '../domain/entities';
import type { AssociatedFigmaDesign } from '../domain/entities/associated-figma-design';
import {
generateAssociatedFigmaDesign,
generateAtlassianDesign,
Expand Down Expand Up @@ -71,6 +72,9 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
'findManyByFileKeyAndConnectInstallationId',
)
.mockResolvedValue(associatedFigmaDesigns);
jest
.spyOn(associatedFigmaDesignRepository, 'upsert')
.mockResolvedValue({} as AssociatedFigmaDesign);
jest
.spyOn(figmaService, 'getAvailableDesignsFromSameFile')
.mockResolvedValue(associatedAtlassianDesigns);
Expand Down Expand Up @@ -109,6 +113,9 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
'findManyByFileKeyAndConnectInstallationId',
)
.mockResolvedValue(associatedFigmaDesigns);
jest
.spyOn(associatedFigmaDesignRepository, 'upsert')
.mockResolvedValue({} as AssociatedFigmaDesign);
jest
.spyOn(figmaService, 'getAvailableDesignsFromSameFile')
.mockResolvedValue(associatedAtlassianDesigns);
Expand Down Expand Up @@ -138,6 +145,9 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
'findManyByFileKeyAndConnectInstallationId',
)
.mockResolvedValue(associatedFigmaDesigns);
jest
.spyOn(associatedFigmaDesignRepository, 'upsert')
.mockResolvedValue({} as AssociatedFigmaDesign);
jest
.spyOn(figmaService, 'getAvailableDesignsFromSameFile')
.mockRejectedValue(new UnauthorizedFigmaServiceError());
Expand All @@ -162,6 +172,9 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
'findManyByFileKeyAndConnectInstallationId',
)
.mockResolvedValue(associatedFigmaDesigns);
jest
.spyOn(associatedFigmaDesignRepository, 'upsert')
.mockResolvedValue({} as AssociatedFigmaDesign);
jest
.spyOn(figmaService, 'getAvailableDesignsFromSameFile')
.mockRejectedValue(error);
Expand Down
2 changes: 1 addition & 1 deletion src/usecases/handle-figma-file-update-event-use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const handleFigmaFileUpdateEventUseCase = {

if (!designs.length) return;

// Update the timestamp for all the designs that updated their dev status
// Update the timestamp for all the designs attached to a node
await Promise.all([
await jiraService.submitDesigns(
designs.map((design) => ({ design })),
Expand Down
21 changes: 12 additions & 9 deletions src/web/routes/figma/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { isNotNullOrUndefined } from '../../../common/predicates';
import { isString } from '../../../common/string-utils';
import { getConfig } from '../../../config';
import type {
AssociatedFigmaDesign,
AtlassianDesign,
ConnectInstallation,
FigmaDesignIdentifier,
FigmaOAuth2UserCredentials,
FigmaTeam,
} from '../../../domain/entities';
Expand Down Expand Up @@ -70,20 +70,22 @@ const FIGMA_OAUTH_TOKEN_ENDPOINT = '/api/oauth/token';
const FIGMA_WEBHOOK_EVENT_ENDPOINT = '/figma/webhook';

function generateAtlassianDesignFromDesignIdAndFileResponse(
designId: FigmaDesignIdentifier,
associatedFigmaDesign: AssociatedFigmaDesign,
fileResponse: GetFileResponse,
) {
let atlassianDesign: AtlassianDesign;
if (!designId.nodeId) {
if (!associatedFigmaDesign.designId.nodeId) {
atlassianDesign = transformFileToAtlassianDesign({
fileKey: designId.fileKey,
fileKey: associatedFigmaDesign.designId.fileKey,
fileResponse,
});
} else {
atlassianDesign = transformNodeToAtlassianDesign({
fileKey: designId.fileKey,
nodeId: designId.nodeId,
fileKey: associatedFigmaDesign.designId.fileKey,
nodeId: associatedFigmaDesign.designId.nodeId,
fileResponse,
prevDevStatus: associatedFigmaDesign.devStatus,
prevLastUpdated: associatedFigmaDesign.lastUpdated,
});
}

Expand Down Expand Up @@ -126,6 +128,7 @@ describe('/figma', () => {
nodeId: `1:${i}`,
}),
connectInstallationId: connectInstallation.id,
lastUpdated: currentDate.toISOString(),
});

await associatedFigmaDesignRepository.upsert(
Expand Down Expand Up @@ -164,7 +167,7 @@ describe('/figma', () => {
const associatedAtlassianDesigns = associatedFigmaDesigns.map(
(design) =>
generateAtlassianDesignFromDesignIdAndFileResponse(
design.designId,
design,
fileResponse,
),
);
Expand Down Expand Up @@ -293,7 +296,7 @@ describe('/figma', () => {
const associatedAtlassianDesigns = associatedFigmaDesigns.map(
(design) =>
generateAtlassianDesignFromDesignIdAndFileResponse(
design.designId,
design,
fileResponse,
),
);
Expand Down Expand Up @@ -351,7 +354,7 @@ describe('/figma', () => {
const associatedAtlassianDesigns = associatedFigmaDesigns.map(
(design) =>
generateAtlassianDesignFromDesignIdAndFileResponse(
design.designId,
design,
fileResponse,
),
);
Expand Down

0 comments on commit 04ea253

Please sign in to comment.