Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
soyombo-baterdene authored Sep 17, 2020
1 parent fedee0a commit 26c5b45
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/__tests__/widgetMutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,38 @@ describe('lead', () => {
mock.restore();
});

test('leadConnect: Already filled', async () => {
const mock = sinon.stub(utils, 'sendRequest').callsFake(() => {
return Promise.resolve('success');
});

const brand = await brandFactory({});
const form = await formFactory({});

const integration = await integrationFactory({
brandId: brand._id,
formId: form._id,
leadData: {
loadType: 'embedded',
isRequireOnce: true,
},
});

const conversation = await conversationFactory({ customerId: '123123', integrationId: integration._id });

const response = await widgetMutations.widgetsLeadConnect(
{},
{
brandCode: brand.code || '',
formCode: form.code || '',
cachedCustomerId: '123123',
},
);
expect(conversation).toBeDefined();
expect(response).toBeNull();
mock.restore();
});

test('saveLead: form not found', async () => {
try {
await widgetMutations.widgetsSaveLead(
Expand Down
3 changes: 2 additions & 1 deletion src/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export const FORM_FIELDS = {
BLANK: '',
NUMBER: 'number',
DATE: 'date',
DATETIME: 'datetime',
EMAIL: 'email',
ALL: ['', 'number', 'date', 'email'],
ALL: ['', 'number', 'date', 'datetime', 'email'],
},
};

Expand Down
9 changes: 8 additions & 1 deletion src/data/resolvers/mutations/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getMessengerData = async (integration: IIntegrationDocument) => {

const widgetMutations = {
// Find integrationId by brandCode
async widgetsLeadConnect(_root, args: { brandCode: string; formCode: string }) {
async widgetsLeadConnect(_root, args: { brandCode: string; formCode: string; cachedCustomerId?: string }) {
const brand = await Brands.findOne({ code: args.brandCode });
const form = await Forms.findOne({ code: args.formCode });

Expand Down Expand Up @@ -112,6 +112,13 @@ const widgetMutations = {
registerOnboardHistory({ type: 'leadIntegrationInstalled', user });
}

if (integ.leadData?.isRequireOnce && args.cachedCustomerId) {
const conversation = await Conversations.findOne({ customerId: args.cachedCustomerId, integrationId: integ.id });
if (conversation) {
return null;
}
}

// return integration details
return {
integration: integ,
Expand Down
1 change: 1 addition & 0 deletions src/data/schema/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const types = `
themeColor: String
callout: JSON,
rules: [InputRule]
isRequireOnce: Boolean
}
input MessengerOnlineHoursSchema {
Expand Down
3 changes: 2 additions & 1 deletion src/data/schema/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export const mutations = `
widgetsLeadConnect(
brandCode: String!,
formCode: String!
formCode: String!,
cachedCustomerId: String
): FormConnectResponse
widgetsSaveLead(
Expand Down
6 changes: 6 additions & 0 deletions src/db/models/definitions/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface ILeadData {
rules?: IRule;
viewCount?: number;
contactsGathered?: number;
isRequireOnce?: boolean;
}

export interface ILeadDataDocument extends ILeadData, Document {
Expand Down Expand Up @@ -259,6 +260,11 @@ export const leadDataSchema = new Schema(
optional: true,
label: 'Rules',
}),
isRequireOnce: field({
type: Boolean,
optional: true,
label: 'Do now show again if already filled out',
}),
},
{ _id: false },
);
Expand Down

0 comments on commit 26c5b45

Please sign in to comment.