fix: Salesforce ownership query (#20405)

* Fix query

* Add test
This commit is contained in:
Joe Au-Yeung
2025-03-27 16:08:09 +00:00
committed by GitHub
parent 50bacf6ea2
commit 7f5534b340
2 changed files with 17 additions and 2 deletions
@@ -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`
);