Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { isEnabled } from '@automattic/calypso-config';
export const A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG =
'a4a-partner-directory-lead-matching';

export const A4A_PARTNER_DIRECTORY_LEAD_MATCHING_PILOT_AGENCY_IDS = new Set( [
232667176, 251102500, 234036126, 234278359, 232640028,
] );

export const isLeadMatchingPilotAgency = ( agencyId?: number ) =>
typeof agencyId === 'number' &&
A4A_PARTNER_DIRECTORY_LEAD_MATCHING_PILOT_AGENCY_IDS.has( agencyId );

export const isLeadMatchingSectionEnabled = () =>
isEnabled( A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
jest.mock( '@automattic/calypso-config', () => ( {
isEnabled: jest.fn(),
} ) );

import { isEnabled } from '@automattic/calypso-config';
import {
A4A_PARTNER_DIRECTORY_LEAD_MATCHING_PILOT_AGENCY_IDS,
isLeadMatchingPilotAgency,
isLeadMatchingSectionEnabled,
} from '../lead-matching-visibility';

const mockedIsEnabled = isEnabled as jest.MockedFunction< typeof isEnabled >;

describe( 'lead matching visibility', () => {
beforeEach( () => {
mockedIsEnabled.mockReset();
} );

it( 'returns true when the global feature flag is enabled', () => {
mockedIsEnabled.mockReturnValue( true );

expect( isLeadMatchingSectionEnabled() ).toBe( true );
expect( isLeadMatchingSectionEnabled( 123 ) ).toBe( true );
} );

it( 'returns true for pilot agencies', () => {
for ( const agencyId of A4A_PARTNER_DIRECTORY_LEAD_MATCHING_PILOT_AGENCY_IDS ) {
expect( isLeadMatchingPilotAgency( agencyId ) ).toBe( true );
}
} );

it( 'returns false for non-pilot agencies', () => {
mockedIsEnabled.mockReturnValue( false );

expect( isLeadMatchingPilotAgency( 123 ) ).toBe( false );
expect( isLeadMatchingPilotAgency() ).toBe( false );
expect( isLeadMatchingSectionEnabled() ).toBe( false );
} );
} );
12 changes: 12 additions & 0 deletions client/state/a8c-for-agencies/agency/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import config from '@automattic/calypso-config';
import { translate } from 'i18n-calypso';
// Required for modular state.
import 'calypso/state/a8c-for-agencies/init';
import { A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG } from 'calypso/a8c-for-agencies/sections/partner-directory/lib/lead-matching-visibility';
import { errorNotice } from 'calypso/state/notices/actions';
import { NoticeActionOptions } from 'calypso/state/notices/types';
import { APIError, Agency, AgencyThunkAction, UserBillingType } from '../types';
Expand All @@ -15,6 +16,10 @@ import {
import { getActiveAgency, isFetchingAgency } from './selectors';
import type { LeadMatchingDetails } from 'calypso/a8c-for-agencies/sections/partner-directory/types';

const LEAD_MATCHING_PILOT_AGENCY_IDS = new Set( [
232667176, 251102500, 234036126, 234278359, 232640028,
] );

export function setActiveAgency( agency: Agency ): AgencyThunkAction {
return ( dispatch, getState ) => {
if ( ! agency || isFetchingAgency( getState() ) ) {
Expand Down Expand Up @@ -152,6 +157,13 @@ export function receiveAgencies( agencies: Agency[] ): AgencyThunkAction {
if ( ! config.isEnabled( 'a4a-partner-directory' ) && newAgency.partner_directory.allowed ) {
config.enable( 'a4a-partner-directory' );
}

if (
! config.isEnabled( A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG ) &&
LEAD_MATCHING_PILOT_AGENCY_IDS.has( newAgency.id )
) {
config.enable( A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG );
}
}
};
}
Expand Down
74 changes: 73 additions & 1 deletion client/state/a8c-for-agencies/agency/test/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
jest.mock( '@automattic/calypso-config', () => ( {
__esModule: true,
default: {
isEnabled: jest.fn(),
enable: jest.fn(),
},
} ) );

import config from '@automattic/calypso-config';
import { A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG } from 'calypso/a8c-for-agencies/sections/partner-directory/lib/lead-matching-visibility';
import { JETPACK_CURRENT_AGENCY_UPDATE } from '../action-types';
import { updateActiveAgencyAvailability, updateActiveAgencyLeadMatching } from '../actions';
import {
receiveAgencies,
updateActiveAgencyAvailability,
updateActiveAgencyLeadMatching,
} from '../actions';
import type { A4AStore, Agency } from '../../types';
import type {
AgencyLeadMatchingProfile,
LeadMatchingDetails,
} from 'calypso/a8c-for-agencies/sections/partner-directory/types';

const mockedConfig = config as jest.Mocked< typeof config >;

const createLeadMatchingDraft = (
overrides: Partial< LeadMatchingDetails > = {}
): LeadMatchingDetails => ( {
Expand Down Expand Up @@ -179,6 +195,12 @@ const isCurrentAgencyUpdateAction = ( action: unknown ): action is CurrentAgency
'activeAgency' in action;

describe( 'a8c-for-agencies agency actions', () => {
beforeEach( () => {
mockedConfig.isEnabled.mockReset();
mockedConfig.enable.mockReset();
mockedConfig.isEnabled.mockReturnValue( false );
} );

describe( '#updateActiveAgencyLeadMatching()', () => {
test( 'merges draft updates against the latest active agency state', () => {
let state = createState(
Expand Down Expand Up @@ -299,4 +321,54 @@ describe( 'a8c-for-agencies agency actions', () => {
).toBe( false );
} );
} );

describe( '#receiveAgencies()', () => {
test( 'enables the lead matching feature flag for pilot agencies', () => {
let state = createState( createAgency() );
const getState = () => state;
const dispatch: jest.Mock = jest.fn( ( actionOrThunk: unknown ) => {
if ( typeof actionOrThunk === 'function' ) {
return actionOrThunk( dispatch, getState, undefined );
}

if ( isCurrentAgencyUpdateAction( actionOrThunk ) ) {
state = {
...state,
a8cForAgencies: {
...state.a8cForAgencies,
agencies: {
...state.a8cForAgencies.agencies,
activeAgency: actionOrThunk.activeAgency,
},
},
};
}

return actionOrThunk;
} );

receiveAgencies( [ createAgency( { id: 232667176 } ) ] )( dispatch, getState, undefined );

expect( mockedConfig.enable ).toHaveBeenCalledWith(
A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG
);
} );

test( 'does not enable the lead matching feature flag for non-pilot agencies', () => {
const getState = () => createState( createAgency() );
const dispatch: jest.Mock = jest.fn( ( actionOrThunk: unknown ) => {
if ( typeof actionOrThunk === 'function' ) {
return actionOrThunk( dispatch, getState, undefined );
}

return actionOrThunk;
} );

receiveAgencies( [ createAgency( { id: 123 } ) ] )( dispatch, getState, undefined );

expect( mockedConfig.enable ).not.toHaveBeenCalledWith(
A4A_PARTNER_DIRECTORY_LEAD_MATCHING_FEATURE_FLAG
);
} );
} );
} );
Loading