Merge remote-tracking branch 'origin/main' into 18368-notification-banner
[arvados.git] / src / services / api-client-authorization-service / api-client-authorization-service.test.ts
index cc1942cf99d7d72e8df9256ec076ff42c4ff21a2..4dd01b8737e57e76d463abe72fcba4f14d780081 100644 (file)
@@ -3,7 +3,6 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import axios, { AxiosInstance } from "axios";
-// import MockAdapter from 'axios-mock-adapter';
 import { ApiClientAuthorizationService } from "./api-client-authorization-service";
 
 
@@ -12,7 +11,6 @@ describe('ApiClientAuthorizationService', () => {
     let serverApi: AxiosInstance;
     let actions;
 
-
     beforeEach(() => {
         serverApi = axios.create();
         actions = {
@@ -26,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' } }
             ));
@@ -42,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', () => {
@@ -57,11 +74,11 @@ describe('ApiClientAuthorizationService', () => {
             await apiClientAuthorizationService.listCollectionSharingTokens(uuid);
             expect(serverApi.get).toHaveBeenCalledWith(
                 `/api_client_authorizations`, {params: {
-                    filters: '[["scopes","=","' + JSON.stringify([
+                    filters: JSON.stringify([["scopes","=",[
                         `GET /arvados/v1/collections/${uuid}`,
                         `GET /arvados/v1/collections/${uuid}/`,
-                        `GET /arvados/v1/keep_services/accessible`,
-                    ]) + '"]]',
+                        'GET /arvados/v1/keep_services/accessible',
+                    ]]]),
                     select: undefined,
                 }}
             );