Files
upstream-rocketchat/apps/meteor/tests/end-to-end/api/push.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

287 lines
7.8 KiB
TypeScript

import { expect } from 'chai';
import { before, describe, it, after } from 'mocha';
import { getCredentials, api, request, credentials } from '../../data/api-data';
import { updateSetting } from '../../data/permissions.helper';
describe('[Push]', () => {
before((done) => getCredentials(done));
describe('POST [/push.token]', () => {
it('should succeed with a valid gcm token', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'gcm',
value: 'token',
appName: 'com.example.rocketchat',
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('result').and.to.be.an('object');
});
});
it('should succeed with a valid apn token', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'apn',
value: 'token',
appName: 'com.example.rocketchat',
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('result').and.to.be.an('object');
});
});
it('should fail if not logged in', async () => {
await request
.post(api('push.token'))
.send({
type: 'gcm',
value: 'token',
appName: 'com.example.rocketchat',
})
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
});
});
it('should fail if missing type', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
value: 'token',
appName: 'com.example.rocketchat',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must have required property 'type'`);
});
});
it('should fail if missing value', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'gcm',
appName: 'com.example.rocketchat',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must have required property 'value'`);
});
});
it('should fail if missing appName', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'gcm',
value: 'token',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must have required property 'appName'`);
});
});
it('should fail if type param is unknown', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'unknownPlatform',
value: 'token',
appName: 'com.example.rocketchat',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must be equal to one of the allowed values`);
});
});
it('should fail if token param is empty', async () => {
await request
.post(api('push.token'))
.set(credentials)
.send({
type: 'gcm',
appName: 'com.example.rocketchat',
value: '',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must NOT have fewer than 1 characters`);
});
});
});
describe('DELETE [/push.token]', () => {
it('should fail if not logged in', async () => {
await request
.delete(api('push.token'))
.send({
token: 'token',
})
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
});
});
it('should fail if missing token key', async () => {
await request
.delete(api('push.token'))
.set(credentials)
.send({})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must have required property 'token'`);
});
});
it('should fail if token is empty', async () => {
await request
.delete(api('push.token'))
.set(credentials)
.send({
token: '',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'invalid-params');
expect(res.body).to.have.property('error').that.includes(`must NOT have fewer than 1 characters`);
});
});
it('should fail if token is invalid', async () => {
await request
.delete(api('push.token'))
.set(credentials)
.send({
token: '123',
})
.expect(404)
.expect((res) => {
expect(res.body).to.have.property('success', false);
});
});
it('should delete a token if valid', async () => {
await request
.delete(api('push.token'))
.set(credentials)
.send({
token: 'token',
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});
});
it('should fail if token is already deleted', async () => {
await request
.delete(api('push.token'))
.set(credentials)
.send({
token: 'token',
})
.expect(404)
.expect((res) => {
expect(res.body).to.have.property('success', false);
});
});
});
describe('[/push.test]', () => {
before(() => updateSetting('Push_enable', false));
it('should fail if not logged in', async () => {
await request
.post(api('push.test'))
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
});
});
it('should fail if push is disabled', async () => {
await request
.post(api('push.test'))
.set(credentials)
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'error-push-disabled');
});
});
});
describe('[/push.info]', () => {
before(() => Promise.all([updateSetting('Push_gateway', 'https://random-gateway.rocket.chat')]));
after(() => Promise.all([updateSetting('Push_gateway', 'https://gateway.rocket.chat')]));
it('should fail if not logged in', async () => {
await request
.get(api('push.info'))
.expect(401)
.expect((res) => {
expect(res.body).to.have.property('status', 'error');
expect(res.body).to.have.property('message');
});
});
it('should succesfully retrieve non default push notification info', async () => {
await request
.get(api('push.info'))
.set(credentials)
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('pushGatewayEnabled', false);
expect(res.body).to.have.property('defaultPushGateway', false);
});
});
it('should succesfully retrieve default push notification info', async () => {
await updateSetting('Push_gateway', 'https://gateway.rocket.chat');
await request
.get(api('push.info'))
.set(credentials)
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('pushGatewayEnabled', false);
expect(res.body).to.have.property('defaultPushGateway', true);
});
});
});
});