1- import { describe , it , expect } from 'vitest' ;
1+ import { beforeAll , describe , it , expect } from 'vitest' ;
22import { setupUnifiedTests , getServices , InitMode } from '../../config/unified-setup' ;
3- import { retryWithBackoff } from '../../utils/helpers' ;
3+ import { wait } from '../../utils/helpers' ;
44
55/**
66 * Integration tests for entity attachment operations (upload, remove)
@@ -69,11 +69,11 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
6969 } ) ;
7070
7171 describe ( 'deleteAttachment' , ( ) => {
72- it ( 'should upload and then delete an attachment via service method' , async ( ) => {
72+ beforeAll ( async ( ) => {
7373 const { entities } = getServices ( ) ;
7474
75- // First upload an attachment so there's something to delete
76- const fileContent = 'Temporary file for delete attachment test ' ;
75+ // Upload once so both delete tests run against an already-propagated attachment
76+ const fileContent = 'Temporary file for delete attachment tests ' ;
7777 const file = new Blob ( [ fileContent ] , { type : 'text/plain' } ) ;
7878
7979 await entities . uploadAttachment (
@@ -83,7 +83,13 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
8383 file ,
8484 ) ;
8585
86- // Now delete the attachment
86+ // Allow time for the API to propagate the upload before delete tests run
87+ await wait ( 2000 ) ;
88+ } ) ;
89+
90+ it ( 'should delete an attachment via service method' , async ( ) => {
91+ const { entities } = getServices ( ) ;
92+
8793 const result = await entities . deleteAttachment (
8894 ATTACHMENT_CONFIG . entityId ,
8995 ATTACHMENT_CONFIG . recordId ,
@@ -93,22 +99,11 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
9399 expect ( result ) . toBeDefined ( ) ;
94100 } ) ;
95101
96- it ( 'should upload and then delete an attachment via entity method' , async ( ) => {
102+ it ( 'should delete an attachment via entity method' , async ( ) => {
97103 const { entities } = getServices ( ) ;
98104
99105 const entity = await entities . getById ( ATTACHMENT_CONFIG . entityId ) ;
100106
101- // First upload an attachment so there's something to delete
102- const fileContent = 'Temporary file for entity method delete test' ;
103- const file = new Blob ( [ fileContent ] , { type : 'text/plain' } ) ;
104-
105- await entity . uploadAttachment (
106- ATTACHMENT_CONFIG . recordId ,
107- ATTACHMENT_CONFIG . fieldName ,
108- file ,
109- ) ;
110-
111- // Now delete the attachment
112107 const result = await entity . deleteAttachment (
113108 ATTACHMENT_CONFIG . recordId ,
114109 ATTACHMENT_CONFIG . fieldName ,
@@ -119,11 +114,11 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
119114 } ) ;
120115
121116 describe ( 'downloadAttachment' , ( ) => {
122- it ( 'should upload and then download an attachment via service method' , async ( ) => {
117+ beforeAll ( async ( ) => {
123118 const { entities } = getServices ( ) ;
124119
125- // First upload an attachment so there's something to download
126- const fileContent = 'Temporary file for download attachment test ' ;
120+ // Upload once so both download tests run against an already-propagated attachment
121+ const fileContent = 'Temporary file for download attachment tests ' ;
127122 const file = new Blob ( [ fileContent ] , { type : 'text/plain' } ) ;
128123
129124 await entities . uploadAttachment (
@@ -133,7 +128,13 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
133128 file ,
134129 ) ;
135130
136- // Now download the attachment
131+ // Allow time for the API to propagate the upload before download tests run
132+ await wait ( 2000 ) ;
133+ } ) ;
134+
135+ it ( 'should download an attachment via service method' , async ( ) => {
136+ const { entities } = getServices ( ) ;
137+
137138 const downloadedFile = await entities . downloadAttachment (
138139 ATTACHMENT_CONFIG . entityId ,
139140 ATTACHMENT_CONFIG . recordId ,
@@ -143,27 +144,14 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
143144 expect ( downloadedFile ) . toBeDefined ( ) ;
144145 } ) ;
145146
146- it ( 'should upload and then download an attachment via entity method' , async ( ) => {
147+ it ( 'should download an attachment via entity method' , async ( ) => {
147148 const { entities } = getServices ( ) ;
148149
149150 const entity = await entities . getById ( ATTACHMENT_CONFIG . entityId ) ;
150151
151- // First upload an attachment so there's something to download
152- const fileContent = 'Temporary file for entity method download test' ;
153- const file = new Blob ( [ fileContent ] , { type : 'text/plain' } ) ;
154-
155- await entity . uploadAttachment (
152+ const downloadedFile = await entity . downloadAttachment (
156153 ATTACHMENT_CONFIG . recordId ,
157154 ATTACHMENT_CONFIG . fieldName ,
158- file ,
159- ) ;
160-
161- // Retry download to handle API propagation delay after upload
162- const downloadedFile = await retryWithBackoff ( ( ) =>
163- entity . downloadAttachment (
164- ATTACHMENT_CONFIG . recordId ,
165- ATTACHMENT_CONFIG . fieldName ,
166- )
167155 ) ;
168156
169157 expect ( downloadedFile ) . toBeDefined ( ) ;
0 commit comments