"Fossies" - the Fresh Open Source Software Archive

Member "Rocket.Chat-4.7.2/apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts" (20 May 2022, 7842 Bytes) of package /linux/www/Rocket.Chat-4.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import { expect } from 'chai';
    2 
    3 import { getCredentials, api, request, credentials } from '../../../data/api-data.js';
    4 import { createVisitor, createLivechatRoom, createAgent } from '../../../data/livechat/rooms.js';
    5 import { updatePermission, updateSetting } from '../../../data/permissions.helper';
    6 
    7 describe('LIVECHAT - rooms', function () {
    8     this.retries(0);
    9 
   10     before((done) => getCredentials(done));
   11 
   12     before((done) => {
   13         updateSetting('Livechat_enabled', true).then(() => {
   14             createAgent()
   15                 .then(() => createVisitor())
   16                 .then((visitor) => createLivechatRoom(visitor.token))
   17                 .then(() => done());
   18         });
   19     });
   20 
   21     describe('livechat/rooms', () => {
   22         it('should return an "unauthorized error" when the user does not have the necessary permission', (done) => {
   23             updatePermission('view-livechat-manager', []).then(() => {
   24                 request
   25                     .get(api('livechat/rooms'))
   26                     .set(credentials)
   27                     .expect('Content-Type', 'application/json')
   28                     .expect(403)
   29                     .expect((res) => {
   30                         expect(res.body).to.have.property('success', false);
   31                         expect(res.body.error).to.be.equal('unauthorized');
   32                     })
   33                     .end(done);
   34             });
   35         });
   36         it('should return an error when the "agents" query parameter is not valid', (done) => {
   37             updatePermission('view-livechat-manager', ['admin']).then(() => {
   38                 request
   39                     .get(api('livechat/rooms?agents=invalid'))
   40                     .set(credentials)
   41                     .expect('Content-Type', 'application/json')
   42                     .expect(400)
   43                     .expect((res) => {
   44                         expect(res.body).to.have.property('success', false);
   45                     })
   46                     .end(done);
   47             });
   48         });
   49         it('should return an error when the "roomName" query parameter is not valid', (done) => {
   50             request
   51                 .get(api('livechat/rooms?roomName[]=invalid'))
   52                 .set(credentials)
   53                 .expect('Content-Type', 'application/json')
   54                 .expect(400)
   55                 .expect((res) => {
   56                     expect(res.body).to.have.property('success', false);
   57                 })
   58                 .end(done);
   59         });
   60         it('should return an error when the "departmentId" query parameter is not valid', (done) => {
   61             request
   62                 .get(api('livechat/rooms?departmentId[]=marcos'))
   63                 .set(credentials)
   64                 .expect('Content-Type', 'application/json')
   65                 .expect(400)
   66                 .expect((res) => {
   67                     expect(res.body).to.have.property('success', false);
   68                 })
   69                 .end(done);
   70         });
   71         it('should return an error when the "open" query parameter is not valid', (done) => {
   72             request
   73                 .get(api('livechat/rooms?open[]=true'))
   74                 .set(credentials)
   75                 .expect('Content-Type', 'application/json')
   76                 .expect(400)
   77                 .expect((res) => {
   78                     expect(res.body).to.have.property('success', false);
   79                 })
   80                 .end(done);
   81         });
   82         it('should return an error when the "tags" query parameter is not valid', (done) => {
   83             request
   84                 .get(api('livechat/rooms?tags=invalid'))
   85                 .set(credentials)
   86                 .expect('Content-Type', 'application/json')
   87                 .expect(400)
   88                 .expect((res) => {
   89                     expect(res.body).to.have.property('success', false);
   90                 })
   91                 .end(done);
   92         });
   93         it('should return an error when the "createdAt" query parameter is not valid', (done) => {
   94             request
   95                 .get(api('livechat/rooms?createdAt=invalid'))
   96                 .set(credentials)
   97                 .expect('Content-Type', 'application/json')
   98                 .expect(400)
   99                 .expect((res) => {
  100                     expect(res.body).to.have.property('success', false);
  101                 })
  102                 .end(done);
  103         });
  104         it('should return an error when the "closedAt" query parameter is not valid', (done) => {
  105             request
  106                 .get(api('livechat/rooms?closedAt=invalid'))
  107                 .set(credentials)
  108                 .expect('Content-Type', 'application/json')
  109                 .expect(400)
  110                 .expect((res) => {
  111                     expect(res.body).to.have.property('success', false);
  112                 })
  113                 .end(done);
  114         });
  115         it('should return an error when the "customFields" query parameter is not valid', (done) => {
  116             request
  117                 .get(api('livechat/rooms?customFields=invalid'))
  118                 .set(credentials)
  119                 .expect('Content-Type', 'application/json')
  120                 .expect(400)
  121                 .expect((res) => {
  122                     expect(res.body).to.have.property('success', false);
  123                 })
  124                 .end(done);
  125         });
  126         it('should return an array of rooms when has no parameters', (done) => {
  127             request
  128                 .get(api('livechat/rooms'))
  129                 .set(credentials)
  130                 .expect('Content-Type', 'application/json')
  131                 .expect(200)
  132                 .expect((res) => {
  133                     expect(res.body).to.have.property('success', true);
  134                     expect(res.body.rooms).to.be.an('array');
  135                     expect(res.body).to.have.property('offset');
  136                     expect(res.body).to.have.property('total');
  137                     expect(res.body).to.have.property('count');
  138                 })
  139                 .end(done);
  140         });
  141         it('should return an array of rooms when the query params is all valid', (done) => {
  142             request
  143                 .get(
  144                     api(`livechat/rooms?agents[]=teste&departamentId=123&open=true&createdAt={"start": "2018-01-26T00:11:22.345Z", "end": "2018-01-26T00:11:22.345Z"}
  145             &closedAt={"start": "2018-01-26T00:11:22.345Z", "end": "2018-01-26T00:11:22.345Z"}&tags[]=rocket
  146             &customFields={"docId": "031041"}&count=3&offset=1&sort={"_updatedAt": 1}&fields={"msgs": 0}&roomName=test`),
  147                 )
  148                 .set(credentials)
  149                 .expect('Content-Type', 'application/json')
  150                 .expect(200)
  151                 .expect((res) => {
  152                     expect(res.body).to.have.property('success', true);
  153                     expect(res.body.rooms).to.be.an('array');
  154                     expect(res.body).to.have.property('offset');
  155                     expect(res.body).to.have.property('total');
  156                     expect(res.body).to.have.property('count');
  157                 })
  158                 .end(done);
  159         });
  160     });
  161 
  162     describe('livechat/room.close', () => {
  163         it('should return an "invalid-token" error when the visitor is not found due to an invalid token', (done) => {
  164             request
  165                 .get(api('livechat/room.close'))
  166                 .set(credentials)
  167                 .expect('Content-Type', 'application/json')
  168                 .expect(400)
  169                 .expect((res) => {
  170                     expect(res.body).to.have.property('success', false);
  171                     expect(res.body.error).to.be.equal('invalid-token');
  172                 })
  173                 .end(done);
  174         });
  175 
  176         it('should return an "invalid-room" error when the room is not found due to invalid token and/or rid', (done) => {
  177             request
  178                 .get(api('livechat/room.close'))
  179                 .set(credentials)
  180                 .expect('Content-Type', 'application/json')
  181                 .expect(400)
  182                 .expect((res) => {
  183                     expect(res.body).to.have.property('success', false);
  184                     expect(res.body.error).to.be.equal('invalid-room');
  185                 })
  186                 .end(done);
  187         });
  188 
  189         it('should return an "room-closed" error when the room is already closed', (done) => {
  190             request
  191                 .get(api('livechat/room.close'))
  192                 .set(credentials)
  193                 .expect('Content-Type', 'application/json')
  194                 .expect(400)
  195                 .expect((res) => {
  196                     expect(res.body).to.have.property('success', false);
  197                     expect(res.body.error).to.be.equal('room-closed');
  198                 })
  199                 .end(done);
  200         });
  201 
  202         it('should return an error when the "rid" query parameter is not valid', (done) => {
  203             request
  204                 .get(api('livechat/rooms?rid=invalid'))
  205                 .set(credentials)
  206                 .expect('Content-Type', 'application/json')
  207                 .expect(400)
  208                 .expect((res) => {
  209                     expect(res.body).to.have.property('success', false);
  210                 })
  211                 .end(done);
  212         });
  213 
  214         it('should return an error when the "token" query parameter is not valid', (done) => {
  215             request
  216                 .get(api('livechat/rooms?token=invalid'))
  217                 .set(credentials)
  218                 .expect('Content-Type', 'application/json')
  219                 .expect(400)
  220                 .expect((res) => {
  221                     expect(res.body).to.have.property('success', false);
  222                 })
  223                 .end(done);
  224         });
  225 
  226         it('should return both the rid and the comment of the room when the query params is all valid', (done) => {
  227             request
  228                 .get(api(`livechat/room.close?rid=123&token=321`))
  229                 .set(credentials)
  230                 .expect('Content-Type', 'application/json')
  231                 .expect(200)
  232                 .expect((res) => {
  233                     expect(res.body).to.have.property('success', true);
  234                     expect(res.body).to.have.property('rid');
  235                     expect(res.body).to.have.property('comment');
  236                 })
  237                 .end(done);
  238         });
  239     });
  240 });