Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/elements/content-sharing/__tests__/sharingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ describe('elements/content-sharing/sharingService', () => {
undefined, // access
undefined, // isDownloadAvailable
undefined, // serverUrl
undefined,
);
expect(mockItemApiInstance.updateSharedLink).toHaveBeenCalledWith(
options,
Expand Down Expand Up @@ -247,6 +248,7 @@ describe('elements/content-sharing/sharingService', () => {
options: {
...options,
access: 'open',
currentExpiresAt: 1700000000000,
isDownloadAvailable: true,
serverUrl: 'https://example.com/server-url',
},
Expand All @@ -268,6 +270,7 @@ describe('elements/content-sharing/sharingService', () => {
'open',
true,
'https://example.com/server-url',
1700000000000,
);
expect(mockItemApiInstance.updateSharedLink).toHaveBeenCalledWith(
options,
Expand Down Expand Up @@ -297,7 +300,13 @@ describe('elements/content-sharing/sharingService', () => {

await service.updateSharedLink(sharedLinkSettings);

expect(convertSharedLinkSettings).toHaveBeenCalledWith(sharedLinkSettings, undefined, undefined, undefined);
expect(convertSharedLinkSettings).toHaveBeenCalledWith(
sharedLinkSettings,
undefined,
undefined,
undefined,
undefined,
);
});

test('should reject with 404 error when hasSharedLink is false', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe('elements/content-sharing/hooks/useSharingService', () => {
onRemoveSharedLink: expect.any(Function),
options: {
access: mockSharedLink.access,
currentExpiresAt: null,
isDownloadAvailable: mockSharedLink.settings.isDownloadAvailable,
id: mockItemId,
permissions: { can_set_share_access, can_share },
Expand Down Expand Up @@ -236,6 +237,7 @@ describe('elements/content-sharing/hooks/useSharingService', () => {
onRemoveSharedLink: expect.any(Function),
options: {
access: mockSharedLink.access,
currentExpiresAt: null,
isDownloadAvailable: mockSharedLink.settings.isDownloadAvailable,
id: mockItemId,
permissions: { can_set_share_access, can_share },
Expand Down
1 change: 1 addition & 0 deletions src/elements/content-sharing/hooks/useSharingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const useSharingService = ({
can_share: sharingServiceProps?.can_share,
},
serverUrl: sharingServiceProps?.serverUrl,
currentExpiresAt: sharedLink?.expiresAt ?? null,
isDownloadAvailable: sharedLink?.settings?.isDownloadAvailable ?? false,
};

Expand Down
5 changes: 3 additions & 2 deletions src/elements/content-sharing/sharingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ItemData {

export interface Options extends ItemData {
access?: string;
currentExpiresAt?: number | null;
isDownloadAvailable?: boolean;
serverUrl?: string;
}
Expand Down Expand Up @@ -69,12 +70,12 @@ export const createSharingService = ({
return Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 }));
}

const { access, isDownloadAvailable, serverUrl } = options;
const { access, currentExpiresAt, isDownloadAvailable, serverUrl } = options;

return new Promise((resolve, reject) => {
itemApiInstance.updateSharedLink(
{ id, permissions },
convertSharedLinkSettings(sharedLinkSettings, access, isDownloadAvailable, serverUrl),
convertSharedLinkSettings(sharedLinkSettings, access, isDownloadAvailable, serverUrl, currentExpiresAt),
data => {
onUpdateSharedLink(data);
resolve(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,291 @@ describe('elements/content-sharing/utils/convertSharingServiceData', () => {

expect(result.unshared_at).toBeNull();
});

test('should omit unshared_at when the submitted date is the same local calendar day', () => {
const settings = {
...mockSettings,
expiration: new Date(2024, 11, 31, 0, 0, 0),
};

const result = convertSharedLinkSettings(
settings,
ACCESS_OPEN,
true,
mockServerUrl,
new Date(2024, 11, 31, 18, 30, 0).getTime(),
);

expect(result.unshared_at).toBeUndefined();
});

test('should include unshared_at when the submitted date is a different local calendar day', () => {
const settings = {
...mockSettings,
expiration: new Date(2024, 11, 31, 0, 0, 0),
};

const result = convertSharedLinkSettings(
settings,
ACCESS_OPEN,
true,
mockServerUrl,
new Date(2024, 11, 30, 23, 0, 0).getTime(),
);

expect(result.unshared_at).toBe('2024-12-31T23:59:59.000Z');
});

test('should include unshared_at when expiration is toggled on and there was no current expiration', () => {
const result = convertSharedLinkSettings(mockSettings, ACCESS_OPEN, true, mockServerUrl, null);

expect(result.unshared_at).toBe('2024-12-31T23:59:59.000Z');
});

test('should set unshared_at to null when expiration is toggled off and there was a current expiration', () => {
const settingsWithoutExpiration = {
...mockSettings,
isExpirationEnabled: false,
};

const result = convertSharedLinkSettings(
settingsWithoutExpiration,
ACCESS_OPEN,
true,
mockServerUrl,
new Date(2024, 11, 31, 18, 30, 0).getTime(),
);

expect(result.unshared_at).toBeNull();
});

test('should include unshared_at when the current expiration argument is omitted', () => {
const result = convertSharedLinkSettings(mockSettings, ACCESS_OPEN, true, mockServerUrl);

expect(result.unshared_at).toBe('2024-12-31T23:59:59.000Z');
});

describe('which shared link fields are sent together', () => {
const sameDay = new Date(2024, 11, 31, 18, 30, 0).getTime();
const otherDay = new Date(2024, 11, 30, 23, 0, 0).getTime();
const sameDaySettings = {
...mockSettings,
expiration: new Date(2024, 11, 31, 0, 0, 0),
};

test.each([
{
name: 'day - same, download, vanity name, no expiration',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: 'vanity-name' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - same, download, no vanity name, no expiration',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: '' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
vanity_url: '',
},
},
{
name: 'day - same, vanity name, download off, no expiration',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: 'vanity-name' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - same, download off, no vanity name, no expiration',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: '' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
vanity_url: '',
},
},
{
name: 'day - different, expiration, download, vanity name',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: 'vanity-name' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: otherDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
unshared_at: '2024-12-31T23:59:59.000Z',
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - different, expiration, download, no vanity name',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: true, vanityName: '' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: otherDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
unshared_at: '2024-12-31T23:59:59.000Z',
vanity_url: '',
},
},
{
name: 'day - different, expiration, vanity name, download off',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: 'vanity-name' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: otherDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
unshared_at: '2024-12-31T23:59:59.000Z',
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - different, expiration, download off, no vanity name',
inputs: {
settings: { ...sameDaySettings, isDownloadEnabled: false, vanityName: '' },
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: otherDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
unshared_at: '2024-12-31T23:59:59.000Z',
vanity_url: '',
},
},
{
name: 'day - off, expiration null, download, vanity name',
inputs: {
settings: {
...sameDaySettings,
isDownloadEnabled: true,
isExpirationEnabled: false,
vanityName: 'vanity-name',
},
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
unshared_at: null,
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - off, expiration null, download, no vanity name',
inputs: {
settings: {
...sameDaySettings,
isDownloadEnabled: true,
isExpirationEnabled: false,
vanityName: '',
},
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: false, can_download: true },
unshared_at: null,
vanity_url: '',
},
},
{
name: 'day - off, expiration null, vanity name, download off',
inputs: {
settings: {
...sameDaySettings,
isDownloadEnabled: false,
isExpirationEnabled: false,
vanityName: 'vanity-name',
},
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: mockServerUrl,
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
unshared_at: null,
vanity_url: 'https://example.com/server-url/vanity-name',
},
},
{
name: 'day - off, expiration null, download off, no vanity name',
inputs: {
settings: {
...sameDaySettings,
isDownloadEnabled: false,
isExpirationEnabled: false,
vanityName: '',
},
access: ACCESS_COMPANY,
isDownloadAvailable: true,
serverUrl: '',
currentExpiresAt: sameDay,
},
expected_body: {
permissions: { can_preview: true, can_download: false },
unshared_at: null,
vanity_url: '',
},
},
])('$name', ({ inputs, expected_body }) => {
const { settings, access, isDownloadAvailable, serverUrl, currentExpiresAt } = inputs;
const result =
currentExpiresAt === undefined
? convertSharedLinkSettings(settings, access, isDownloadAvailable, serverUrl)
: convertSharedLinkSettings(
settings,
access,
isDownloadAvailable,
serverUrl,
currentExpiresAt,
);

expect(result).toEqual(expected_body);
});
});
});

describe('vanity URL', () => {
Expand Down
Loading
Loading