1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import axios, { AxiosInstance } from "axios";
6 // import MockAdapter from 'axios-mock-adapter';
7 import { ApiClientAuthorizationService } from "./api-client-authorization-service";
10 describe('ApiClientAuthorizationService', () => {
11 let apiClientAuthorizationService: ApiClientAuthorizationService;
12 let serverApi: AxiosInstance;
17 serverApi = axios.create();
19 progressFn: jest.fn(),
21 apiClientAuthorizationService = new ApiClientAuthorizationService(serverApi, actions);
24 describe('createCollectionSharingToken', () => {
25 it('should return error on invalid collection uuid', () => {
26 expect(() => apiClientAuthorizationService.createCollectionSharingToken("foo")).toThrowError("UUID foo is not a collection");
29 it('should make a create request with proper scopes', async () => {
30 serverApi.post = jest.fn(() => Promise.resolve(
31 { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } }
33 const uuid = 'zzzzz-4zz18-0123456789abcde'
34 await apiClientAuthorizationService.createCollectionSharingToken(uuid);
35 expect(serverApi.post).toHaveBeenCalledWith(
36 '/api_client_authorizations', {
38 `GET /arvados/v1/collections/${uuid}`,
39 `GET /arvados/v1/collections/${uuid}/`,
40 `GET /arvados/v1/keep_services/accessible`,
47 describe('listCollectionSharingToken', () => {
48 it('should return error on invalid collection uuid', () => {
49 expect(() => apiClientAuthorizationService.listCollectionSharingTokens("foo")).toThrowError("UUID foo is not a collection");
52 it('should make a list request with proper scopes', async () => {
53 serverApi.get = jest.fn(() => Promise.resolve(
54 { data: { items: [{}] } }
56 const uuid = 'zzzzz-4zz18-0123456789abcde'
57 await apiClientAuthorizationService.listCollectionSharingTokens(uuid);
58 expect(serverApi.get).toHaveBeenCalledWith(
59 `/api_client_authorizations`, {params: {
60 filters: '[["scopes","=","' + JSON.stringify([
61 `GET /arvados/v1/collections/${uuid}`,
62 `GET /arvados/v1/collections/${uuid}/`,
63 `GET /arvados/v1/keep_services/accessible`,