Skip to content
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
15 changes: 10 additions & 5 deletions src/libs/actions/Domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import enhanceParameters from '@libs/Network/enhanceParameters';
import {generateAccountID} from '@libs/UserUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
import type {SecurityGroupKey} from '@src/types/onyx/Domain';
import type {DomainSecurityGroupErrors} from '@src/types/onyx/DomainErrors';
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -765,7 +765,7 @@ function revokeDomainAdminAccess(domainAccountID: number, accountID: number) {
/**
* Removes the domain
*/
function resetDomain(domainAccountID: number, domainName: string, domain: Domain) {
function resetDomain(domainAccountID: number, domainName: string) {
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -777,10 +777,15 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
value: null,
value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},
},
];
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN_ERRORS>> = [
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.DOMAIN | typeof ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS | typeof ONYXKEYS.COLLECTION.DOMAIN_ERRORS>> = [
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
value: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS}${domainAccountID}`,
Expand All @@ -800,7 +805,7 @@ function resetDomain(domainAccountID: number, domainName: string, domain: Domain
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.DOMAIN}${domainAccountID}`,
value: domain,
value: {pendingAction: null},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/domain/DomainResetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function DomainResetDomainPage({route}: DomainResetDomainPageProps) {
Log.hmmm('Domain data is missing or there are more than 1 admin left');
return;
}
resetDomain(route.params.domainAccountID, domainName, domain);
resetDomain(route.params.domainAccountID, domainName);
Navigation.goBack(ROUTES.WORKSPACES_LIST.route);
};

Expand Down
16 changes: 8 additions & 8 deletions tests/actions/DomainTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Domain, DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
import type {DomainSecurityGroup, UserSecurityGroupData} from '@src/types/onyx';
import type {SecurityGroupKey} from '@src/types/onyx/Domain';
import type {BaseVacationDelegate} from '@src/types/onyx/VacationDelegate';
import type PrefixedRecord from '@src/types/utils/PrefixedRecord';
Expand Down Expand Up @@ -90,20 +90,20 @@ describe('actions/Domain', () => {
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());
const domainAccountID = 123;
const domainName = 'test.com';
const domain = {
accountID: domainAccountID,
} as Domain;

resetDomain(domainAccountID, domainName, domain);
resetDomain(domainAccountID, domainName);

expect(apiWriteSpy).toHaveBeenCalledWith(
WRITE_COMMANDS.DELETE_DOMAIN,
{domainAccountID, domainName},
{
optimisticData: [expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}), expect.objectContaining({value: null})],
successData: [expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})],
optimisticData: [
expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}),
expect.objectContaining({value: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}),
],
successData: [expect.objectContaining({value: null}), expect.objectContaining({value: {pendingAction: null}}), expect.objectContaining({value: {errors: null}})],
failureData: [
expect.objectContaining({value: domain}),
expect.objectContaining({value: {pendingAction: null}}),
expect.objectContaining({value: {pendingAction: null}}),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
expect.objectContaining({value: {errors: expect.any(Object)}}),
Expand Down
Loading