Skip to content

Commit 1f2ca7d

Browse files
committed
test(content-sharing): cover shared link field combinations
1 parent 852e934 commit 1f2ca7d

1 file changed

Lines changed: 222 additions & 0 deletions

File tree

‎src/elements/content-sharing/utils/__tests__/convertSharingServiceData.test.ts‎

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,228 @@ describe('elements/content-sharing/utils/convertSharingServiceData', () => {
182182

183183
expect(result.unshared_at).toBe('2024-12-31T23:59:59.000Z');
184184
});
185+
186+
describe('which shared link fields are sent together', () => {
187+
const sameDay = new Date(2024, 11, 31, 18, 30, 0).getTime();
188+
const otherDay = new Date(2024, 11, 30, 23, 0, 0).getTime();
189+
const sameDaySettings = {
190+
...mockSettings,
191+
expiration: new Date(2024, 11, 31, 0, 0, 0),
192+
};
193+
194+
test.each([
195+
{
196+
name: 'day - same, download, vanity name, no expiration',
197+
inputs: {
198+
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: 'vanity-name' },
199+
access: ACCESS_COMPANY,
200+
isDownloadAvailable: true,
201+
serverUrl: mockServerUrl,
202+
currentExpiresAt: sameDay,
203+
},
204+
expected_body: {
205+
permissions: { can_preview: false, can_download: true },
206+
vanity_url: 'https://example.com/server-url/vanity-name',
207+
},
208+
},
209+
{
210+
name: 'day - same, download, no vanity name, no expiration',
211+
inputs: {
212+
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: '' },
213+
access: ACCESS_COMPANY,
214+
isDownloadAvailable: true,
215+
serverUrl: '',
216+
currentExpiresAt: sameDay,
217+
},
218+
expected_body: {
219+
permissions: { can_preview: false, can_download: true },
220+
vanity_url: '',
221+
},
222+
},
223+
{
224+
name: 'day - same, vanity name, download off, no expiration',
225+
inputs: {
226+
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: 'vanity-name' },
227+
access: ACCESS_COMPANY,
228+
isDownloadAvailable: true,
229+
serverUrl: mockServerUrl,
230+
currentExpiresAt: sameDay,
231+
},
232+
expected_body: {
233+
permissions: { can_preview: true, can_download: false },
234+
vanity_url: 'https://example.com/server-url/vanity-name',
235+
},
236+
},
237+
{
238+
name: 'day - same, download off, no vanity name, no expiration',
239+
inputs: {
240+
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: '' },
241+
access: ACCESS_COMPANY,
242+
isDownloadAvailable: true,
243+
serverUrl: '',
244+
currentExpiresAt: sameDay,
245+
},
246+
expected_body: {
247+
permissions: { can_preview: true, can_download: false },
248+
vanity_url: '',
249+
},
250+
},
251+
{
252+
name: 'day - different, expiration, download, vanity name',
253+
inputs: {
254+
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: 'vanity-name' },
255+
access: ACCESS_COMPANY,
256+
isDownloadAvailable: true,
257+
serverUrl: mockServerUrl,
258+
currentExpiresAt: otherDay,
259+
},
260+
expected_body: {
261+
permissions: { can_preview: false, can_download: true },
262+
unshared_at: '2024-12-31T23:59:59.000Z',
263+
vanity_url: 'https://example.com/server-url/vanity-name',
264+
},
265+
},
266+
{
267+
name: 'day - different, expiration, download, no vanity name',
268+
inputs: {
269+
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: '' },
270+
access: ACCESS_COMPANY,
271+
isDownloadAvailable: true,
272+
serverUrl: '',
273+
currentExpiresAt: otherDay,
274+
},
275+
expected_body: {
276+
permissions: { can_preview: false, can_download: true },
277+
unshared_at: '2024-12-31T23:59:59.000Z',
278+
vanity_url: '',
279+
},
280+
},
281+
{
282+
name: 'day - different, expiration, vanity name, download off',
283+
inputs: {
284+
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: 'vanity-name' },
285+
access: ACCESS_COMPANY,
286+
isDownloadAvailable: true,
287+
serverUrl: mockServerUrl,
288+
currentExpiresAt: otherDay,
289+
},
290+
expected_body: {
291+
permissions: { can_preview: true, can_download: false },
292+
unshared_at: '2024-12-31T23:59:59.000Z',
293+
vanity_url: 'https://example.com/server-url/vanity-name',
294+
},
295+
},
296+
{
297+
name: 'day - different, expiration, download off, no vanity name',
298+
inputs: {
299+
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: '' },
300+
access: ACCESS_COMPANY,
301+
isDownloadAvailable: true,
302+
serverUrl: '',
303+
currentExpiresAt: otherDay,
304+
},
305+
expected_body: {
306+
permissions: { can_preview: true, can_download: false },
307+
unshared_at: '2024-12-31T23:59:59.000Z',
308+
vanity_url: '',
309+
},
310+
},
311+
{
312+
name: 'day - off, expiration null, download, vanity name',
313+
inputs: {
314+
settings: {
315+
...sameDaySettings,
316+
isDownloadEnabled: true,
317+
isExpirationEnabled: false,
318+
vanityName: 'vanity-name',
319+
},
320+
access: ACCESS_COMPANY,
321+
isDownloadAvailable: true,
322+
serverUrl: mockServerUrl,
323+
currentExpiresAt: sameDay,
324+
},
325+
expected_body: {
326+
permissions: { can_preview: false, can_download: true },
327+
unshared_at: null,
328+
vanity_url: 'https://example.com/server-url/vanity-name',
329+
},
330+
},
331+
{
332+
name: 'day - off, expiration null, download, no vanity name',
333+
inputs: {
334+
settings: {
335+
...sameDaySettings,
336+
isDownloadEnabled: true,
337+
isExpirationEnabled: false,
338+
vanityName: '',
339+
},
340+
access: ACCESS_COMPANY,
341+
isDownloadAvailable: true,
342+
serverUrl: '',
343+
currentExpiresAt: sameDay,
344+
},
345+
expected_body: {
346+
permissions: { can_preview: false, can_download: true },
347+
unshared_at: null,
348+
vanity_url: '',
349+
},
350+
},
351+
{
352+
name: 'day - off, expiration null, vanity name, download off',
353+
inputs: {
354+
settings: {
355+
...sameDaySettings,
356+
isDownloadEnabled: false,
357+
isExpirationEnabled: false,
358+
vanityName: 'vanity-name',
359+
},
360+
access: ACCESS_COMPANY,
361+
isDownloadAvailable: true,
362+
serverUrl: mockServerUrl,
363+
currentExpiresAt: sameDay,
364+
},
365+
expected_body: {
366+
permissions: { can_preview: true, can_download: false },
367+
unshared_at: null,
368+
vanity_url: 'https://example.com/server-url/vanity-name',
369+
},
370+
},
371+
{
372+
name: 'day - off, expiration null, download off, no vanity name',
373+
inputs: {
374+
settings: {
375+
...sameDaySettings,
376+
isDownloadEnabled: false,
377+
isExpirationEnabled: false,
378+
vanityName: '',
379+
},
380+
access: ACCESS_COMPANY,
381+
isDownloadAvailable: true,
382+
serverUrl: '',
383+
currentExpiresAt: sameDay,
384+
},
385+
expected_body: {
386+
permissions: { can_preview: true, can_download: false },
387+
unshared_at: null,
388+
vanity_url: '',
389+
},
390+
},
391+
])('$name', ({ inputs, expected_body }) => {
392+
const { settings, access, isDownloadAvailable, serverUrl, currentExpiresAt } = inputs;
393+
const result =
394+
currentExpiresAt === undefined
395+
? convertSharedLinkSettings(settings, access, isDownloadAvailable, serverUrl)
396+
: convertSharedLinkSettings(
397+
settings,
398+
access,
399+
isDownloadAvailable,
400+
serverUrl,
401+
currentExpiresAt,
402+
);
403+
404+
expect(result).toEqual(expected_body);
405+
});
406+
});
185407
});
186408

187409
describe('vanity URL', () => {

0 commit comments

Comments
 (0)