Skip to content

Commit

Permalink
feat(seed): set permission id on seed
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 23, 2020
1 parent bdb2e82 commit 77af37f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/seed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
MODEL_NAME_PERMISSION,
MODEL_NAME_PREDEFINE,
MODEL_NAME_PARTY,
MODEL_NAME_EVENT,
Expand Down Expand Up @@ -1229,15 +1230,25 @@ export const seedCase = (optns, done) => {
*/
export const seedPermissions = (done) => {
debug('Start Seeding Permissions Data');
// TODO: ensure collision free ids

// generate object id
const transform = (seed) => {
const merged = mergeObjects(
{ _id: objectIdFor(MODEL_NAME_PERMISSION, seed.wildcard) },
seed
);
return merged;
};

// prepare permissions seed stages
const seedResourcePermissions = (next) => {
return Permission.seed((error) => next(error));
const options = { transform };
return Permission.seed(options, (error) => next(error));
};
const seedPredefineNamespacePermissions = (next) => {
const namespacePermissions = listPermissions();
return Permission.seed(namespacePermissions, (error) => next(error));
const data = listPermissions();
const options = { data, transform };
return Permission.seed(options, (error) => next(error));
};
const stages = [seedResourcePermissions, seedPredefineNamespacePermissions];

Expand Down
8 changes: 4 additions & 4 deletions test/integration/seed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import '@codetanzania/ewea-event';
import '@codetanzania/ewea-dispatch';
import '@codetanzania/ewea-case';

describe('seed', () => {
describe.only('seed', () => {
const { BASE_PATH, DATA_PATH, SEED_PATH } = process.env;

before(() => {
Expand Down Expand Up @@ -173,15 +173,15 @@ describe('seed', () => {
});
});

it('should seed predefines', (done) => {
it('should seed predefine', (done) => {
const optns = {};
seedPredefine(optns, (error) => {
expect(error).to.not.exist;
done(error);
});
});

it('should seed parties', (done) => {
it('should seed party', (done) => {
seedParty({}, (error) => {
expect(error).to.not.exist;
done(error);
Expand All @@ -195,7 +195,7 @@ describe('seed', () => {
});
});

it('should seed permissions', (done) => {
it.only('should seed permissions', (done) => {
seedPermissions((error) => {
expect(error).to.not.exist;
done(error);
Expand Down

0 comments on commit 77af37f

Please sign in to comment.