m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
791 stars 39 forks source link

Cognito - SignUpCommand issue #91

Closed chops318 closed 2 years ago

chops318 commented 2 years ago

Checklist

Bug description I am using NestJS and trying to mock out the CognitoIdentityProvider. I do this in a beforeEach via

    const cognito = new CognitoIdentityProvider({ region: 'local' });
    cgMock = mockClient(cognito);
    cgMock.reset();
  it('creates a new user', async () => {
    const mockUser = {
      UserSub: 'asdfasfd',
      $metadata: {
        attempts: 0,
      },
      UserConfirmed: true,
      AuthenticationResult: {
        RefreshToken: 'asdfafsd',
        AccessToken: 'asdfasdf',
        IdToken: 'asdfasdf',
      },
    };

    cgMock.onAnyCommand().resolvesOnce(mockUser);
    const user = await service.register({
      username: '<email>',
      password: '<password>',
    });
    expect(user).toBeDefined();
    expect(user.email).toBe('<email>');
  });

If I set a bogus ClientId, I get a ResourceNotFoundException, but if I provide a valid ClientId, the command gets sent onto Cognito and the user is created. I'm unsure if I am doing anything incorrect, but it seems as if the mock is not intercepting the command sent to Cognito

Environment

TylerSustare commented 1 year ago

@chops318 Why did you close this? Did you find a solution? I'm running into the same issue with DynamoDB and query commands #141