16115: Adds expiration date param to sharing url service method.
[arvados-workbench2.git] / src / services / api-client-authorization-service / api-client-authorization-service.test.ts
index 3a271f5396e8f9e516ee1257c6e9c91fda6a1d1c..4dd01b8737e57e76d463abe72fcba4f14d780081 100644 (file)
@@ -24,7 +24,7 @@ describe('ApiClientAuthorizationService', () => {
             expect(() => apiClientAuthorizationService.createCollectionSharingToken("foo")).toThrowError("UUID foo is not a collection");
         });
 
-        it('should make a create request with proper scopes', async () => {
+        it('should make a create request with proper scopes and no expiration date', async () => {
             serverApi.post = jest.fn(() => Promise.resolve(
                 { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
             ));
@@ -40,6 +40,25 @@ describe('ApiClientAuthorizationService', () => {
                 }
             );
         });
+
+        it('should make a create request with proper scopes and expiration date', async () => {
+            serverApi.post = jest.fn(() => Promise.resolve(
+                { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
+            ));
+            const uuid = 'zzzzz-4zz18-0123456789abcde'
+            const expDate = new Date(2022, 8, 28, 12, 0, 0);
+            await apiClientAuthorizationService.createCollectionSharingToken(uuid, expDate);
+            expect(serverApi.post).toHaveBeenCalledWith(
+                '/api_client_authorizations', {
+                    scopes: [
+                        `GET /arvados/v1/collections/${uuid}`,
+                        `GET /arvados/v1/collections/${uuid}/`,
+                        `GET /arvados/v1/keep_services/accessible`,
+                    ],
+                    expires_at: expDate.toUTCString()
+                }
+            );
+        });
     });
 
     describe('listCollectionSharingToken', () => {