Skip to content
This repository was archived by the owner on Mar 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/permission.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const PermissionSchema = new Schema({
*/
resource: {
type: String,
// string: true,
trim: true,
required: true,
searchable: true,
Expand Down Expand Up @@ -98,6 +99,7 @@ const PermissionSchema = new Schema({
*/
action: {
type: String,
// String: true,
trim: true,
lowercase: true,
required: true,
Expand Down Expand Up @@ -158,6 +160,7 @@ const PermissionSchema = new Schema({
wildcard: {
type: String,
trim: true,
// String: true,
lowercase: true,
required: true,
searchable: true,
Expand Down
79 changes: 78 additions & 1 deletion test/unit/permission.model.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';


/* dependencies */
const path = require('path');
const { expect } = require('chai');
Expand All @@ -16,6 +15,84 @@ describe('Permission', function () {

describe('Validations', function () {
//TODO
describe('resource', function () {

it('should check for required', function (done) {
const permission = new Permission();
permission.validate(function (error) {
expect(error.errors.resource).to.exist;
expect(error.errors.resource.value).to.be.undefined;
expect(error.errors.resource.kind).to.be.equal('required');
done();
});
});

it('should check for validity', function (done) {
const permission = Permission.fake();
permission.validate(function (error) {
expect(error).to.not.exist;
done();
});
});

it('should check for validity', function (done) {
const permission = Permission.fake();
permission.resource = 1234;
permission.validate(function (error) {
expect(error).to.not.exist;
done();
});
});

});

describe('Actions', function () {

it('should check actiion error validity', function (done) {
const permission = new Permission({
resource:null,
action:null
});

permission.validate(function (error) {
expect(error.errors.action).to.exist;
done();
});
});

it('should check the validity ', function (done) {
const actions = Permission.fake();
actions.validate(function (error) {
expect(error).to.not.exist;
done();
});
});
});

describe('Wildcard', function () {

it('should check for wildcard error validation', function (done) {
const wildcard = {
wildcard: null,
resource: null,
action:null
};
const permission = new Permission(wildcard);
permission.validate(function (error) {
expect(error).to.exist;
done();
});
});

it('should check for wildcard validity', function (done) {
const permission = Permission.fake();
permission.validate(function (error) {
expect(error).to.not.exist;
done();
});
});
});

});


Expand Down