You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3. Then in all your tests you will need to set up the database and context. The default values are configured so you can easily mount an empty and operational database.
@@ -131,3 +128,41 @@ cy.setUpApi({
131
128
},
132
129
});
133
130
```
131
+
132
+
### Mock Uploaded files
133
+
134
+
If you need to have files in the mocked server, you can use the `uploadedFiles` array of the `setupApi`. The following are steps to follow if you want to upload and retrieve a file for an app.
135
+
136
+
1. Create a new `AppSetting` and add it in the `appSettings` array of the `setupApi` (in the Cypress test of the frontend).
137
+
138
+
```ts
139
+
// MOCK_FILE_APP_SETTING
140
+
{
141
+
id: mockFileSettingId,
142
+
name: 'file', // should be named `file`! Do not change it!
143
+
data: {
144
+
path: `apps/app-setting/${item.id}/${mockFileSettingId}`, // This path should be mocked in the MSW! If you want to use another path, you just have to mock it.
145
+
},
146
+
item,
147
+
creator,
148
+
createdAt,
149
+
updatedAt,
150
+
};
151
+
```
152
+
153
+
2. Load a file and transform it into a `File` type. With Cypress, have a look to `cy.fixtures` (put the `setupApi` in the `then` callback).
154
+
3. Add the loaded file in the array.
155
+
156
+
```ts
157
+
uploadedFiles: [
158
+
{
159
+
id: MOCK_FILE_APP_SETTING.id,
160
+
file,
161
+
},
162
+
],
163
+
```
164
+
165
+
4. Use the mocked route `GET /app-items/app-settings/:appSettingId/download` (or your mocked route) to retrieve the path of the file.
166
+
5. Use the result of the previous request to download the file. In this example, it's the route `GET /download-app-setting-url/:appSettingId`.
167
+
168
+
Another solution could be to upload your file from the Cypress test, by using the route `/app-items/app-settings-/upload?id=:itemId` for example.
0 commit comments