aws-sdk-client-mock icon indicating copy to clipboard operation
aws-sdk-client-mock copied to clipboard

Type errors mocking Secrets Manager SDK

Open joshuacoveauth0 opened this issue 2 years ago • 0 comments

Checklist

  • [x] I have read Caveats documentation and didn't find a solution for this problem there.

Bug description When attempting to mock AWS Secrets Manager with the code below, getting Type errors on the SecretsManagerClient and GetSecretValueCommand. These errors persist when installing @aws-sdk/types and when pinning all aws-sdk packages to the same version.

import {
    SecretsManagerClient,
    GetSecretValueCommand
  } from '@aws-sdk/client-secrets-manager';
  import { generateDotEnvContents } from '../utils';
  import { getSecretsFromSecretManager } from '../aws';

  describe('with aws mocked', () => {
     const smMock = mockClient(SecretsManagerClient);
     smMock.on(GetSecretValueCommand).resolves({ 
       SecretString: JSON.stringify({ my_secret_key: 'my_secret_value' })
     });

    beforeEach(() => { 
      smMock.reset();
    });

    it('does stuff', async () => {
      const result = await generateDotEnvContents(dotEnvPath)

      expect(result).toEqual({
        DOMAIN: 'my-domain.com',
        MY_SECRET: 'my-secret',
        MY_SECRET_2: 'my-secret-2'
      })

      expect(smMock).toHaveReceivedCommandTimes(GetSecretValueCommand, 1);
    })
  })

Reproduction

Environment

  • Node version: v16.16.0
  • Testing lib and version: jest 28.1.3
  • Typescript version: 4.7.4
  • AWS SDK v3 Client mock version: 1.0.0, 2.0.0
  • AWS JS SDK libs and versions:
    • "@aws-sdk/client-secrets-manager": "^3.171.0", or 3.142.0

joshuacoveauth0 avatar Sep 27 '22 18:09 joshuacoveauth0