@@ -2,12 +2,14 @@ import { v4 as uuidv4 } from 'uuid';
22
33import { handleFigmaFileUpdateEventUseCase } from './handle-figma-file-update-event-use-case' ;
44
5+ import * as launchDarkly from '../config/launch_darkly' ;
56import { FigmaTeamAuthStatus } from '../domain/entities' ;
67import {
78 generateAssociatedFigmaDesign ,
89 generateAtlassianDesign ,
910 generateConnectInstallation ,
1011 generateFigmaDesignIdentifier ,
12+ generateFigmaFileWebhook ,
1113 generateFigmaTeam ,
1214} from '../domain/entities/testing' ;
1315import {
@@ -20,8 +22,65 @@ import {
2022 connectInstallationRepository ,
2123 figmaTeamRepository ,
2224} from '../infrastructure/repositories' ;
25+ import type { FigmaWebhookInfo } from '../web/routes/figma' ;
2326
2427describe ( 'handleFigmaFileUpdateEventUseCase' , ( ) => {
28+ describe ( 'file webhook' , ( ) => {
29+ beforeEach ( ( ) => {
30+ jest . spyOn ( launchDarkly , 'getLDClient' ) . mockResolvedValue ( null ) ;
31+ jest . spyOn ( launchDarkly , 'getFeatureFlag' ) . mockResolvedValue ( true ) ;
32+ } ) ;
33+ it ( 'should handle file webhook events' , async ( ) => {
34+ const connectInstallation = generateConnectInstallation ( ) ;
35+ jest
36+ . spyOn ( connectInstallationRepository , 'get' )
37+ . mockResolvedValue ( connectInstallation ) ;
38+
39+ const figmaFileWebhook = generateFigmaFileWebhook ( {
40+ createdBy : {
41+ connectInstallationId : connectInstallation . id ,
42+ atlassianUserId : uuidv4 ( ) ,
43+ } ,
44+ } ) ;
45+ const fileKey = uuidv4 ( ) ;
46+ const associatedFigmaDesigns = [ 1 , 2 , 3 ] . map ( ( i ) =>
47+ generateAssociatedFigmaDesign ( {
48+ designId : generateFigmaDesignIdentifier ( {
49+ fileKey,
50+ nodeId : `${ i } :${ i } ` ,
51+ } ) ,
52+ connectInstallationId : connectInstallation . id ,
53+ } ) ,
54+ ) ;
55+ jest
56+ . spyOn (
57+ associatedFigmaDesignRepository ,
58+ 'findManyByFileKeyAndConnectInstallationId' ,
59+ )
60+ . mockResolvedValue ( associatedFigmaDesigns ) ;
61+ const associatedAtlassianDesigns = associatedFigmaDesigns . map (
62+ ( figmaDesign ) =>
63+ generateAtlassianDesign ( {
64+ id : figmaDesign . designId . toAtlassianDesignId ( ) ,
65+ } ) ,
66+ ) ;
67+ jest
68+ . spyOn ( figmaService , 'getAvailableDesignsFromSameFile' )
69+ . mockResolvedValue ( associatedAtlassianDesigns ) ;
70+
71+ jest . spyOn ( jiraService , 'submitDesigns' ) . mockResolvedValue ( ) ;
72+
73+ const webhookInfo : FigmaWebhookInfo = {
74+ figmaFileWebhook,
75+ webhookType : 'file' ,
76+ } ;
77+ await handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ;
78+ expect ( jiraService . submitDesigns ) . toHaveBeenCalledWith (
79+ associatedAtlassianDesigns ,
80+ connectInstallation ,
81+ ) ;
82+ } ) ;
83+ } ) ;
2584 describe ( 'error handling' , ( ) => {
2685 const connectInstallation = generateConnectInstallation ( ) ;
2786 const figmaTeam = generateFigmaTeam ( {
@@ -44,7 +103,11 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
44103 . mockRejectedValue ( new UnauthorizedFigmaServiceError ( ) ) ;
45104 jest . spyOn ( figmaTeamRepository , 'updateAuthStatus' ) . mockResolvedValue ( ) ;
46105
47- await handleFigmaFileUpdateEventUseCase . execute ( figmaTeam , fileKey ) ;
106+ const webhookInfo : FigmaWebhookInfo = {
107+ figmaTeam,
108+ webhookType : 'team' ,
109+ } ;
110+ await handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ;
48111
49112 expect ( figmaTeamRepository . updateAuthStatus ) . toHaveBeenCalledWith (
50113 figmaTeam . id ,
@@ -75,7 +138,11 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
75138 . mockResolvedValue ( associatedAtlassianDesigns ) ;
76139 jest . spyOn ( jiraService , 'submitDesigns' ) . mockResolvedValue ( ) ;
77140
78- await handleFigmaFileUpdateEventUseCase . execute ( figmaTeam , fileKey ) ;
141+ const webhookInfo : FigmaWebhookInfo = {
142+ figmaTeam,
143+ webhookType : 'team' ,
144+ } ;
145+ await handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ;
79146
80147 expect ( figmaTeamRepository . updateAuthStatus ) . not . toHaveBeenCalled ( ) ;
81148 expect ( jiraService . submitDesigns ) . toHaveBeenCalledWith (
@@ -111,7 +178,11 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
111178 . mockResolvedValue ( associatedAtlassianDesigns ) ;
112179 jest . spyOn ( jiraService , 'submitDesigns' ) . mockResolvedValue ( ) ;
113180
114- await handleFigmaFileUpdateEventUseCase . execute ( figmaTeam , fileKey ) ;
181+ const webhookInfo : FigmaWebhookInfo = {
182+ figmaTeam,
183+ webhookType : 'team' ,
184+ } ;
185+ await handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ;
115186
116187 expect ( jiraService . submitDesigns ) . toHaveBeenCalledWith (
117188 associatedAtlassianDesigns ,
@@ -138,7 +209,11 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
138209 . mockRejectedValue ( new UnauthorizedFigmaServiceError ( ) ) ;
139210 jest . spyOn ( figmaTeamRepository , 'updateAuthStatus' ) . mockResolvedValue ( ) ;
140211
141- await handleFigmaFileUpdateEventUseCase . execute ( figmaTeam , fileKey ) ;
212+ const webhookInfo : FigmaWebhookInfo = {
213+ figmaTeam,
214+ webhookType : 'team' ,
215+ } ;
216+ await handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ;
142217
143218 expect ( figmaTeamRepository . updateAuthStatus ) . toHaveBeenCalledWith (
144219 figmaTeam . id ,
@@ -166,8 +241,12 @@ describe('handleFigmaFileUpdateEventUseCase', () => {
166241 . mockRejectedValue ( error ) ;
167242 jest . spyOn ( jiraService , 'submitDesigns' ) ;
168243
244+ const webhookInfo : FigmaWebhookInfo = {
245+ figmaTeam,
246+ webhookType : 'team' ,
247+ } ;
169248 await expect (
170- handleFigmaFileUpdateEventUseCase . execute ( figmaTeam , fileKey ) ,
249+ handleFigmaFileUpdateEventUseCase . execute ( webhookInfo , fileKey ) ,
171250 ) . rejects . toStrictEqual ( error ) ;
172251 expect ( jiraService . submitDesigns ) . not . toHaveBeenCalled ( ) ;
173252 } ) ;
0 commit comments