|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as sinon from 'sinon'; |
| 3 | + |
| 4 | +// eslint-disable-next-line @typescript-eslint/no-restricted-imports |
| 5 | +import { AutomatedCallbackWorkflow } from '../../../../../src/cmap/auth/mongodb_oidc/automated_callback_workflow'; |
| 6 | +// eslint-disable-next-line @typescript-eslint/no-restricted-imports |
| 7 | +import { callback } from '../../../../../src/cmap/auth/mongodb_oidc/gcp_machine_workflow'; |
| 8 | +// eslint-disable-next-line @typescript-eslint/no-restricted-imports |
| 9 | +import { TokenCache } from '../../../../../src/cmap/auth/mongodb_oidc/token_cache'; |
| 10 | +import { Connection, MongoCredentials } from '../../../../mongodb'; |
| 11 | + |
| 12 | +describe('AutomatedCallbackWorkflow', function () { |
| 13 | + describe('#execute', function () { |
| 14 | + context('when the cache has a token', function () { |
| 15 | + context('when the connection has no token', function () { |
| 16 | + const cache = new TokenCache(); |
| 17 | + const connection = sinon.createStubInstance(Connection); |
| 18 | + const credentials = sinon.createStubInstance(MongoCredentials); |
| 19 | + const workflow = new AutomatedCallbackWorkflow(cache, callback); |
| 20 | + sinon.stub(workflow, 'finishAuthentication').returns(Promise.resolve()); |
| 21 | + |
| 22 | + beforeEach(function () { |
| 23 | + cache.put({ accessToken: 'test', expiresInSeconds: 7200 }); |
| 24 | + workflow.execute(connection, credentials); |
| 25 | + }); |
| 26 | + |
| 27 | + afterEach(function () { |
| 28 | + sinon.restore(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('sets the token on the connection', async function () { |
| 32 | + expect(connection.accessToken).to.equal('test'); |
| 33 | + }); |
| 34 | + }); |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments