Skip to content

Commit

Permalink
remove openPersonalDetails, update test to call openPublicProfilePage…
Browse files Browse the repository at this point in the history
… instead
  • Loading branch information
grgia committed Apr 5, 2024
1 parent f09f94b commit bfd8fb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 51 deletions.
38 changes: 0 additions & 38 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,43 +234,6 @@ function updateSelectedTimezone(selectedTimezone: SelectedTimezone) {
Navigation.goBack(ROUTES.SETTINGS_TIMEZONE);
}

/**
* Fetches additional personal data like legal name, date of birth, address
*/
function openPersonalDetails() {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: true,
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: false,
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
isLoading: false,
},
},
];

API.read(READ_COMMANDS.OPEN_PERSONAL_DETAILS, {}, {optimisticData, successData, failureData});
}

/**
* Fetches public profile info about a given user.
* The API will only return the accountID, displayName, and avatar for the user
Expand Down Expand Up @@ -443,7 +406,6 @@ function clearAvatarErrors() {
export {
clearAvatarErrors,
deleteAvatar,
openPersonalDetails,
openPublicProfilePage,
updateAddress,
updateAutomaticTimezone,
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/PrivatePersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ type PrivatePersonalDetails = {

/** User's home address */
address?: Address;

/** Whether we are loading the data via the API */
isLoading?: boolean;
};

export default PrivatePersonalDetails;
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/NetworkTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('NetworkTests', () => {
HttpUtils.xhr = mockedXhr;

// This should first trigger re-authentication and then a Failed to fetch
PersonalDetails.openPersonalDetails();
PersonalDetails.openPublicProfilePage(TEST_USER_ACCOUNT_ID);
return waitForBatchedUpdates()
.then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}))
.then(() => {
Expand All @@ -119,11 +119,11 @@ describe('NetworkTests', () => {
return waitForBatchedUpdates();
})
.then(() => {
// Then we will eventually have 1 call to OpenPersonalDetailsPage and 1 calls to Authenticate
const callsToOpenPersonalDetails = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'OpenPersonalDetailsPage');
// Then we will eventually have 1 call to OpenPublicProfilePage and 1 calls to Authenticate
const callsToOpenPublicProfilePage = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'OpenPublicProfilePage');
const callsToAuthenticate = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'Authenticate');

expect(callsToOpenPersonalDetails.length).toBe(1);
expect(callsToOpenPublicProfilePage.length).toBe(1);
expect(callsToAuthenticate.length).toBe(1);
});
});
Expand All @@ -143,7 +143,7 @@ describe('NetworkTests', () => {
const mockedXhr = jest.fn();
mockedXhr

// And mock the first call to openPersonalDetails return with an expired session code
// And mock the first call to openPublicProfilePage return with an expired session code
.mockImplementationOnce(() =>
Promise.resolve({
jsonCode: CONST.JSON_CODE.NOT_AUTHENTICATED,
Expand Down Expand Up @@ -176,17 +176,17 @@ describe('NetworkTests', () => {
// And then make 3 API READ requests in quick succession with an expired authToken and handle the response
// It doesn't matter which requests these are really as all the response is mocked we just want to see
// that we get re-authenticated
PersonalDetails.openPersonalDetails();
PersonalDetails.openPersonalDetails();
PersonalDetails.openPersonalDetails();
PersonalDetails.openPublicProfilePage(TEST_USER_ACCOUNT_ID);
PersonalDetails.openPublicProfilePage(TEST_USER_ACCOUNT_ID);
PersonalDetails.openPublicProfilePage(TEST_USER_ACCOUNT_ID);
return waitForBatchedUpdates();
})
.then(() => {
// We should expect to see the three calls to OpenApp, but only one call to Authenticate.
// And we should also see the reconnection callbacks triggered.
const callsToOpenPersonalDetails = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'OpenPersonalDetailsPage');
const callsToopenPublicProfilePage = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'OpenPublicProfilePage');
const callsToAuthenticate = (HttpUtils.xhr as Mock).mock.calls.filter(([command]) => command === 'Authenticate');
expect(callsToOpenPersonalDetails.length).toBe(3);
expect(callsToopenPublicProfilePage.length).toBe(3);
expect(callsToAuthenticate.length).toBe(1);
expect(reconnectionCallbacksSpy.mock.calls.length).toBe(3);
});
Expand Down

0 comments on commit bfd8fb9

Please sign in to comment.