|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import {strict as assert} from 'assert'; |
| 16 | + |
| 17 | +import * as nock from 'nock'; |
| 18 | + |
| 19 | +import {PassThroughClient} from '../src'; |
| 20 | + |
| 21 | +describe('AuthClient', () => { |
| 22 | + before(async () => { |
| 23 | + nock.disableNetConnect(); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(async () => { |
| 27 | + nock.cleanAll(); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('#getAccessToken', () => { |
| 31 | + it('should return an empty object', async () => { |
| 32 | + const client = new PassThroughClient(); |
| 33 | + const token = await client.getAccessToken(); |
| 34 | + |
| 35 | + assert.deepEqual(token, {}); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('#getRequestHeaders', () => { |
| 40 | + it('should return an empty object', async () => { |
| 41 | + const client = new PassThroughClient(); |
| 42 | + const token = await client.getRequestHeaders(); |
| 43 | + |
| 44 | + assert.deepEqual(token, {}); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('#request', () => { |
| 49 | + it('should return the expected response', async () => { |
| 50 | + const url = 'https://google.com'; |
| 51 | + const example = {test: 'payload'}; |
| 52 | + const scope = nock(url).get('/').reply(200, example); |
| 53 | + |
| 54 | + const client = new PassThroughClient(); |
| 55 | + const response = await client.request({url}); |
| 56 | + |
| 57 | + assert.deepEqual(response.data, example); |
| 58 | + |
| 59 | + scope.done(); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments