1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import axios, { AxiosInstance } from "axios";
6 import { ApiClientAuthorizationService } from "./api-client-authorization-service";
9 describe('ApiClientAuthorizationService', () => {
10 let apiClientAuthorizationService: ApiClientAuthorizationService;
11 let serverApi: AxiosInstance;
15 serverApi = axios.create();
17 progressFn: jest.fn(),
19 apiClientAuthorizationService = new ApiClientAuthorizationService(serverApi, actions);
22 describe('createCollectionSharingToken', () => {
23 it('should return error on invalid collection uuid', () => {
24 expect(() => apiClientAuthorizationService.createCollectionSharingToken("foo")).toThrowError("UUID foo is not a collection");
27 it('should make a create request with proper scopes and no expiration date', async () => {
28 serverApi.post = jest.fn(() => Promise.resolve(
29 { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
31 const uuid = 'zzzzz-4zz18-0123456789abcde'
32 await apiClientAuthorizationService.createCollectionSharingToken(uuid);
33 expect(serverApi.post).toHaveBeenCalledWith(
34 '/api_client_authorizations', {
36 `GET /arvados/v1/collections/${uuid}`,
37 `GET /arvados/v1/collections/${uuid}/`,
38 `GET /arvados/v1/keep_services/accessible`,
44 it('should make a create request with proper scopes and expiration date', async () => {
45 serverApi.post = jest.fn(() => Promise.resolve(
46 { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
48 const uuid = 'zzzzz-4zz18-0123456789abcde'
49 const expDate = new Date(2022, 8, 28, 12, 0, 0);
50 await apiClientAuthorizationService.createCollectionSharingToken(uuid, expDate);
51 expect(serverApi.post).toHaveBeenCalledWith(
52 '/api_client_authorizations', {
54 `GET /arvados/v1/collections/${uuid}`,
55 `GET /arvados/v1/collections/${uuid}/`,
56 `GET /arvados/v1/keep_services/accessible`,
58 expires_at: expDate.toUTCString()
64 describe('listCollectionSharingToken', () => {
65 it('should return error on invalid collection uuid', () => {
66 expect(() => apiClientAuthorizationService.listCollectionSharingTokens("foo")).toThrowError("UUID foo is not a collection");
69 it('should make a list request with proper scopes', async () => {
70 serverApi.get = jest.fn(() => Promise.resolve(
71 { data: { items: [{}] } }
73 const uuid = 'zzzzz-4zz18-0123456789abcde'
74 await apiClientAuthorizationService.listCollectionSharingTokens(uuid);
75 expect(serverApi.get).toHaveBeenCalledWith(
76 `/api_client_authorizations`, {params: {
77 filters: JSON.stringify([["scopes","=",[
78 `GET /arvados/v1/collections/${uuid}`,
79 `GET /arvados/v1/collections/${uuid}/`,
80 'GET /arvados/v1/keep_services/accessible',