@@ -572,4 +572,19 @@ describe("SalesforceCRMService", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAccountBasedOnEmailDomainOfContacts", () => {
|
||||
it("should return the account ID based on email domain", async () => {
|
||||
const querySpy = vi.spyOn(mockConnection, "query");
|
||||
querySpy.mockResolvedValueOnce(accountQueryResponse);
|
||||
|
||||
await service.getAccountBasedOnEmailDomainOfContacts("test@example.com");
|
||||
expect(querySpy).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
`SELECT Id, OwnerId, Owner.Email, Website FROM Account WHERE Website IN (${service.getAllPossibleAccountWebsiteFromEmailDomain(
|
||||
"example.com"
|
||||
)}) LIMIT 1`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -941,14 +941,14 @@ export default class SalesforceCRMService implements CRM {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
private async getAccountBasedOnEmailDomainOfContacts(email: string) {
|
||||
public async getAccountBasedOnEmailDomainOfContacts(email: string) {
|
||||
const conn = await this.conn;
|
||||
const emailDomain = email.split("@")[1];
|
||||
const log = logger.getSubLogger({ prefix: [`[getAccountBasedOnEmailDomainOfContacts]:${email}`] });
|
||||
log.info("Querying first account matching email domain", safeStringify({ emailDomain }));
|
||||
// First check if an account has the same website as the email domain of the attendee
|
||||
const accountQuery = await conn.query(
|
||||
`SELECT Id, OwnerId, Owner.Email, Owner.Website FROM Account WHERE Website IN (${this.getAllPossibleAccountWebsiteFromEmailDomain(
|
||||
`SELECT Id, OwnerId, Owner.Email, Website FROM Account WHERE Website IN (${this.getAllPossibleAccountWebsiteFromEmailDomain(
|
||||
emailDomain
|
||||
)}) LIMIT 1`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user