Skip to content

Commit da9db3a

Browse files
committed
fix(integration): move upload attachment to beforeAll in download tests
1 parent 69c3aed commit da9db3a

File tree

1 file changed

+23
-55
lines changed

1 file changed

+23
-55
lines changed

tests/integration/shared/data-fabric/attachment.integration.test.ts

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { beforeAll, describe, it, expect } from 'vitest';
22
import { 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)
@@ -68,22 +68,24 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
6868
});
6969
});
7070

71-
describe('deleteAttachment', () => {
72-
it('should upload and then delete an attachment via service method', async () => {
73-
const { entities } = getServices();
71+
async function uploadAndWait(content: string): Promise<void> {
72+
const { entities } = getServices();
73+
const file = new Blob([content], { type: 'text/plain' });
74+
await entities.uploadAttachment(
75+
ATTACHMENT_CONFIG.entityId,
76+
ATTACHMENT_CONFIG.recordId,
77+
ATTACHMENT_CONFIG.fieldName,
78+
file,
79+
);
80+
await wait(2000);
81+
}
7482

75-
// First upload an attachment so there's something to delete
76-
const fileContent = 'Temporary file for delete attachment test';
77-
const file = new Blob([fileContent], { type: 'text/plain' });
83+
describe('deleteAttachment', () => {
84+
beforeAll(() => uploadAndWait('Temporary file for delete attachment tests'));
7885

79-
await entities.uploadAttachment(
80-
ATTACHMENT_CONFIG.entityId,
81-
ATTACHMENT_CONFIG.recordId,
82-
ATTACHMENT_CONFIG.fieldName,
83-
file,
84-
);
86+
it('should delete an attachment via service method', async () => {
87+
const { entities } = getServices();
8588

86-
// Now delete the attachment
8789
const result = await entities.deleteAttachment(
8890
ATTACHMENT_CONFIG.entityId,
8991
ATTACHMENT_CONFIG.recordId,
@@ -93,22 +95,11 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
9395
expect(result).toBeDefined();
9496
});
9597

96-
it('should upload and then delete an attachment via entity method', async () => {
98+
it('should delete an attachment via entity method', async () => {
9799
const { entities } = getServices();
98100

99101
const entity = await entities.getById(ATTACHMENT_CONFIG.entityId);
100102

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
112103
const result = await entity.deleteAttachment(
113104
ATTACHMENT_CONFIG.recordId,
114105
ATTACHMENT_CONFIG.fieldName,
@@ -119,21 +110,11 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
119110
});
120111

121112
describe('downloadAttachment', () => {
122-
it('should upload and then download an attachment via service method', async () => {
123-
const { entities } = getServices();
124-
125-
// First upload an attachment so there's something to download
126-
const fileContent = 'Temporary file for download attachment test';
127-
const file = new Blob([fileContent], { type: 'text/plain' });
113+
beforeAll(() => uploadAndWait('Temporary file for download attachment tests'));
128114

129-
await entities.uploadAttachment(
130-
ATTACHMENT_CONFIG.entityId,
131-
ATTACHMENT_CONFIG.recordId,
132-
ATTACHMENT_CONFIG.fieldName,
133-
file,
134-
);
115+
it('should download an attachment via service method', async () => {
116+
const { entities } = getServices();
135117

136-
// Now download the attachment
137118
const downloadedFile = await entities.downloadAttachment(
138119
ATTACHMENT_CONFIG.entityId,
139120
ATTACHMENT_CONFIG.recordId,
@@ -143,27 +124,14 @@ describe.skipIf(!hasAttachmentConfig).each(modes)(
143124
expect(downloadedFile).toBeDefined();
144125
});
145126

146-
it('should upload and then download an attachment via entity method', async () => {
127+
it('should download an attachment via entity method', async () => {
147128
const { entities } = getServices();
148129

149130
const entity = await entities.getById(ATTACHMENT_CONFIG.entityId);
150131

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(
132+
const downloadedFile = await entity.downloadAttachment(
156133
ATTACHMENT_CONFIG.recordId,
157134
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-
)
167135
);
168136

169137
expect(downloadedFile).toBeDefined();

0 commit comments

Comments
 (0)