Skip to content

Commit

Permalink
regression: not use visitor prop for omnichannel endpoint (#34262)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
  • Loading branch information
sampaiodiego and KevLehman authored Dec 20, 2024
1 parent 475120d commit 35de31c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
6 changes: 3 additions & 3 deletions apps/meteor/app/livechat/server/api/v1/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['view-livechat-contact'], validateParams: isGETOmnichannelContactsCheckExistenceProps },
{
async get() {
const { contactId, visitor, email, phone } = this.queryParams;
const { contactId, email, phone } = this.queryParams;

const contact = await (visitor ? getContactByChannel(visitor) : LivechatContacts.countByContactInfo({ contactId, email, phone }));
const contact = await LivechatContacts.countByContactInfo({ contactId, email, phone });

return API.v1.success({ exists: !!contact });
return API.v1.success({ exists: contact > 0 });
},
},
);
Expand Down
34 changes: 1 addition & 33 deletions apps/meteor/tests/end-to-end/api/livechat/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ describe('LIVECHAT - contacts', () => {

describe('[GET] omnichannel/contacts.checkExistence', () => {
let contactId: string;
let association: ILivechatContactVisitorAssociation;
let roomId: string;

const email = faker.internet.email().toLowerCase();
Expand All @@ -1027,13 +1026,6 @@ describe('LIVECHAT - contacts', () => {

const room = await createLivechatRoom(visitor.token);
roomId = room._id;
association = {
visitorId: visitor._id,
source: {
type: room.source.type,
id: room.source.id,
},
};
});

after(async () => Promise.all([restorePermissionToRoles('view-livechat-contact'), closeOmnichannelRoom(roomId)]));
Expand All @@ -1054,25 +1046,6 @@ describe('LIVECHAT - contacts', () => {
expect(res.body).to.have.property('exists', false);
});

it('should confirm a contact exists when checking by visitor association', async () => {
const res = await request.get(api(`omnichannel/contacts.checkExistence`)).set(credentials).query({ visitor: association });

expect(res.status).to.be.equal(200);
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('exists', true);
});

it('should confirm a contact does not exist when checking by visitor association', async () => {
const res = await request
.get(api(`omnichannel/contacts.checkExistence`))
.set(credentials)
.query({ visitor: { ...association, visitorId: 'invalid-id' } });

expect(res.status).to.be.equal(200);
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('exists', false);
});

it('should confirm a contact exists when checking by email', async () => {
const res = await request.get(api(`omnichannel/contacts.checkExistence`)).set(credentials).query({ email });

Expand Down Expand Up @@ -1126,22 +1099,17 @@ describe('LIVECHAT - contacts', () => {
"must have required property 'contactId'",
"must have required property 'email'",
"must have required property 'phone'",
"must have required property 'visitor'",
'must match exactly one schema in oneOf [invalid-params]',
]);
});

it('should return an error if more than one field is provided', async () => {
const res = await request
.get(api(`omnichannel/contacts.checkExistence`))
.set(credentials)
.query({ contactId, visitor: association, email, phone });
const res = await request.get(api(`omnichannel/contacts.checkExistence`)).set(credentials).query({ contactId, email, phone });

expectInvalidParams(res, [
'must NOT have additional properties',
'must NOT have additional properties',
'must NOT have additional properties',
'must NOT have additional properties',
'must match exactly one schema in oneOf [invalid-params]',
]);
});
Expand Down
12 changes: 1 addition & 11 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import type {
SMSProviderResponse,
ILivechatTriggerActionResponse,
ILivechatContact,
ILivechatContactVisitorAssociation,
ILivechatContactChannel,
IUser,
} from '@rocket.chat/core-typings';
Expand Down Expand Up @@ -1336,7 +1335,7 @@ const POSTUpdateOmnichannelContactsSchema = {

export const isPOSTUpdateOmnichannelContactsProps = ajv.compile<POSTUpdateOmnichannelContactsProps>(POSTUpdateOmnichannelContactsSchema);

type GETOmnichannelContactsProps = { contactId?: string; visitor?: ILivechatContactVisitorAssociation };
type GETOmnichannelContactsProps = { contactId?: string };

export const ContactVisitorAssociationSchema = {
type: 'object',
Expand Down Expand Up @@ -1410,7 +1409,6 @@ type GETOmnichannelContactsCheckExistenceProps = {
contactId?: string;
email?: string;
phone?: string;
visitor?: ILivechatContactVisitorAssociation;
};

const GETOmnichannelContactsCheckExistenceSchema = {
Expand Down Expand Up @@ -1452,14 +1450,6 @@ const GETOmnichannelContactsCheckExistenceSchema = {
required: ['phone'],
additionalProperties: false,
},
{
type: 'object',
properties: {
visitor: ContactVisitorAssociationSchema,
},
required: ['visitor'],
additionalProperties: false,
},
],
};

Expand Down

0 comments on commit 35de31c

Please sign in to comment.