Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Oct 22, 2024
1 parent a14fb11 commit 51f7517
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(baseSnippet),
expect(result.body).to.containEql(_.omit(baseSnippet, 'updateACL')),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin']),
(baseSnippetId = result.body.id)
Expand Down Expand Up @@ -112,7 +115,13 @@ describe('Basesnippet', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(baseSnippet)
expect(result.body[0]).to.containEql(
_.omit(baseSnippet, 'updateACL'),
),
expect(result.body[0].updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -133,7 +142,15 @@ describe('Basesnippet', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(baseSnippet))
.then(
result => (
expect(result.body).to.containEql(_.omit(baseSnippet, 'updateACL')),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down Expand Up @@ -463,11 +480,16 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(_.omit(baseSnippet, 'ownerGroup')),
expect(result.body).to.containEql(
_.omit(baseSnippet, ['ownerGroup', 'updateACL']),
),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin'])
Expand Down Expand Up @@ -505,14 +527,19 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(_.omit(baseSnippet, 'createACL')),
expect(result.body).to.containEql(
_.omit(baseSnippet, ['createACL', 'updateACL']),
),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql([
'basesnippetAcceptance',
'aNewCreateACL',
]),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin'])
Expand Down Expand Up @@ -558,6 +585,7 @@ describe('Basesnippet', function (this: Suite) {
expect(result.body.updateACL).to.be.eql([
'anUpdateACL',
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
Expand Down Expand Up @@ -854,26 +882,6 @@ describe('Basesnippet', function (this: Suite) {
});
});

it(`patch snippet by id with non-authorised user should return 404`, async () => {
const bs = await client
.post('/basesnippets')
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({
..._.omit(baseSnippet, 'updateACL'),
updateACL: ['nonAuthorised'],
});
await client
.patch(`/basesnippets/${bs.body.id}`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({name: 'something'})
.expect(404)
.catch(err => {
throw err;
});
});

[404, 204].forEach(t => {
it(`delete snippet should return ${t}`, async () => {
await client
Expand Down
25 changes: 22 additions & 3 deletions sci-log-db/src/__tests__/acceptance/file.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Client, expect} from '@loopback/testlab';
import {Suite} from 'mocha';
import {SciLogDbApplication} from '../..';
import {clearDatabase, createUserToken, setupApplication} from './test-helper';
import _ from 'lodash';

describe('File controller services', function (this: Suite) {
this.timeout(1000);
Expand Down Expand Up @@ -50,8 +51,12 @@ describe('File controller services', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(fileSnippet),
expect(result.body).to.containEql(_.omit(fileSnippet, 'updateACL')),
expect(result.body.snippetType).to.be.eql('image'),
expect(result.body.updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
]),
(fileSnippetId = result.body.id)
),
)
Expand Down Expand Up @@ -95,7 +100,13 @@ describe('File controller services', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(fileSnippet)
expect(result.body[0]).to.containEql(
_.omit(fileSnippet, 'updateACL'),
),
expect(result.body[0].updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -116,7 +127,15 @@ describe('File controller services', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(fileSnippet))
.then(
result => (
expect(result.body).to.containEql(_.omit(fileSnippet, 'updateACL')),
expect(result.body.updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Client, expect} from '@loopback/testlab';
import {Suite} from 'mocha';
import {SciLogDbApplication} from '../..';
import {clearDatabase, createUserToken, setupApplication} from './test-helper';
import _ from 'lodash';

describe('Paragraph', function (this: Suite) {
this.timeout(5000);
Expand Down Expand Up @@ -50,9 +51,15 @@ describe('Paragraph', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(paragraphSnippet),
expect(result.body).to.containEql(
_.omit(paragraphSnippet, 'updateACL'),
),
expect(result.body.snippetType).to.be.eql('paragraph'),
expect(result.body.linkType).to.be.eql('paragraph'),
expect(result.body.updateACL).to.be.eql([
'paragraphAcceptance',
'[email protected]',
]),
(paragraphSnippetId = result.body.id)
),
)
Expand Down Expand Up @@ -96,8 +103,14 @@ describe('Paragraph', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(paragraphSnippet),
expect(result.body[0]).not.to.have.key('htmlTextcontent')
expect(result.body[0]).to.containEql(
_.omit(paragraphSnippet, 'updateACL'),
),
expect(result.body[0]).not.to.have.key('htmlTextcontent'),
expect(result.body[0].updateACL).to.be.eql([
'paragraphAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -118,7 +131,17 @@ describe('Paragraph', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(paragraphSnippet))
.then(
result => (
expect(result.body).to.containEql(
_.omit(paragraphSnippet, 'updateACL'),
),
expect(result.body.updateACL).to.be.eql([
'paragraphAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down
25 changes: 22 additions & 3 deletions sci-log-db/src/__tests__/acceptance/task.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Client, expect} from '@loopback/testlab';
import {Suite} from 'mocha';
import {SciLogDbApplication} from '../..';
import {clearDatabase, createUserToken, setupApplication} from './test-helper';
import _ from 'lodash';

describe('TaskRepositorySnippet', function (this: Suite) {
this.timeout(5000);
Expand Down Expand Up @@ -49,8 +50,12 @@ describe('TaskRepositorySnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(taskSnippet),
expect(result.body).to.containEql(_.omit(taskSnippet, 'updateACL')),
expect(result.body.snippetType).to.containEql('task'),
expect(result.body.updateACL).to.be.eql([
'taskAcceptance',
'[email protected]',
]),
(taskSnippetId = result.body.id)
),
)
Expand Down Expand Up @@ -94,7 +99,13 @@ describe('TaskRepositorySnippet', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(taskSnippet)
expect(result.body[0]).to.containEql(
_.omit(taskSnippet, 'updateACL'),
),
expect(result.body[0].updateACL).to.be.eql([
'taskAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -115,7 +126,15 @@ describe('TaskRepositorySnippet', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(taskSnippet))
.then(
result => (
expect(result.body).to.containEql(_.omit(taskSnippet, 'updateACL')),
expect(result.body.updateACL).to.be.eql([
'taskAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down

0 comments on commit 51f7517

Please sign in to comment.