diff --git a/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts b/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts index 4cdb79a13bd..08394a09aa9 100644 --- a/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts @@ -81,7 +81,23 @@ describe('fetchDevices', () => { }); it('should fetch devices and parse client response correctly', async () => { - expect(await fetchDevices()).toEqual([apiOutputDevice]); + const { + 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({ diff --git a/packages/auth/src/providers/cognito/apis/fetchDevices.ts b/packages/auth/src/providers/cognito/apis/fetchDevices.ts index c0dc69f22f4..5fda1b8fefc 100644 --- a/packages/auth/src/providers/cognito/apis/fetchDevices.ts +++ b/packages/auth/src/providers/cognito/apis/fetchDevices.ts @@ -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'; @@ -77,7 +77,7 @@ const parseDevicesResponse = async ( {}, ); - return { + const result: AWSAuthDevice = { id, name: deviceName, attributes, @@ -91,6 +91,8 @@ const parseDevicesResponse = async ( ? new Date(DeviceLastAuthenticatedDate * 1000) : undefined, }; + + return result; }, ); }; diff --git a/packages/auth/src/types/models.ts b/packages/auth/src/types/models.ts index 1655de572e8..0b286866d6f 100644 --- a/packages/auth/src/types/models.ts +++ b/packages/auth/src/types/models.ts @@ -332,4 +332,5 @@ export interface AWSAuthUser { */ export interface AuthDevice { id: string; + name?: string; }