Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(auth): update FetchDevicesOutput output type to include name attribute #14186

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/auth/__tests__/providers/cognito/fetchDevices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,23 @@ describe('fetchDevices', () => {
});

it('should fetch devices and parse client response correctly', async () => {
expect(await fetchDevices()).toEqual([apiOutputDevice]);
const {
Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably update all API unit tests to

  • use a wrapper to catch input type issues
  • destructure result object to catch output type issues
    (reference)

id,
name,
attributes,
createDate,
lastAuthenticatedDate,
lastModifiedDate,
} = (await fetchDevices())[0];
expect(id).toEqual(apiOutputDevice.id);
expect(name).toEqual(apiOutputDevice.name);
expect(attributes).toEqual(apiOutputDevice.attributes);
expect(createDate).toEqual(apiOutputDevice.createDate);
expect(lastAuthenticatedDate).toEqual(
apiOutputDevice.lastAuthenticatedDate,
);
expect(lastModifiedDate).toEqual(apiOutputDevice.lastModifiedDate);

expect(mockListDevices).toHaveBeenCalledWith(
expect.objectContaining({ region: 'us-west-2' }),
expect.objectContaining({
Expand Down
6 changes: 4 additions & 2 deletions packages/auth/src/providers/cognito/apis/fetchDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { FetchDevicesOutput } from '../types';
import { AWSAuthDevice, FetchDevicesOutput } from '../types';
import { DeviceType } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider/types';
import { assertAuthTokens } from '../utils/types';
import { getRegionFromUserPoolId } from '../../../foundation/parsers';
Expand Down Expand Up @@ -77,7 +77,7 @@ const parseDevicesResponse = async (
{},
);

return {
const result: AWSAuthDevice = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be

devices.map<AWSAuthDevice>()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm by this 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried this as well but TS only enforces mandatory keys

id,
name: deviceName,
attributes,
Expand All @@ -91,6 +91,8 @@ const parseDevicesResponse = async (
? new Date(DeviceLastAuthenticatedDate * 1000)
: undefined,
};

return result;
},
);
};
1 change: 1 addition & 0 deletions packages/auth/src/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,5 @@ export interface AWSAuthUser {
*/
export interface AuthDevice {
id: string;
name?: string;
}
Loading