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', 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`,
45 describe('listCollectionSharingToken', () => {
46 it('should return error on invalid collection uuid', () => {
47 expect(() => apiClientAuthorizationService.listCollectionSharingTokens("foo")).toThrowError("UUID foo is not a collection");
50 it('should make a list request with proper scopes', async () => {
51 serverApi.get = jest.fn(() => Promise.resolve(
52 { data: { items: [{}] } }
54 const uuid = 'zzzzz-4zz18-0123456789abcde'
55 await apiClientAuthorizationService.listCollectionSharingTokens(uuid);
56 expect(serverApi.get).toHaveBeenCalledWith(
57 `/api_client_authorizations`, {params: {
58 filters: '[["scopes","=","' + JSON.stringify([
59 `GET /arvados/v1/collections/${uuid}`,
60 `GET /arvados/v1/collections/${uuid}/`,
61 `GET /arvados/v1/keep_services/accessible`,