Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
feat(permission): restrict user permissions by brand
Browse files Browse the repository at this point in the history
close #517
  • Loading branch information
batamar committed Aug 9, 2019
1 parent b59575f commit 03f785f
Show file tree
Hide file tree
Showing 113 changed files with 5,047 additions and 4,911 deletions.
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pipeline:
branch:
- master
- develop
- staging
event:
- push

Expand Down Expand Up @@ -90,6 +91,7 @@ pipeline:
branch:
- master
- develop
- staging
event:
- push

Expand Down
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ PORT_CRONS=3600

# workers
PORT_WORKERS=3700

USE_BRAND_RESTRICTIONS=false
142 changes: 71 additions & 71 deletions src/__tests__/activityLogQueries.test.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
import * as faker from 'faker';
import { graphqlRequest } from '../db/connection';
import { activityLogFactory } from '../db/factories';
import { ActivityLogs } from '../db/models';
import { ACTIVITY_ACTIONS, ACTIVITY_CONTENT_TYPES, ACTIVITY_TYPES } from '../db/models/definitions/constants';

import './setup.ts';

describe('activityLogQueries', () => {
const commonParamDefs = `
$contentType: String!,
$contentId: String!,
$activityType: String!,
$limit: Int,
`;

const commonParams = `
contentType: $contentType
contentId: $contentId
activityType: $activityType
limit: $limit
`;

const qryActivityLogs = `
query activityLogs(${commonParamDefs}) {
activityLogs(${commonParams}) {
_id
action
id
createdAt
content
by {
type
details {
avatar
fullName
position
}
}
}
}
`;

afterEach(async () => {
// Clearing test data
await ActivityLogs.deleteMany({});
});

test('Activity log list', async () => {
const contentType = ACTIVITY_CONTENT_TYPES.CUSTOMER;
const activityType = ACTIVITY_TYPES.INTERNAL_NOTE;
const contentId = faker.random.uuid();

for (let i = 0; i < 3; i++) {
await activityLogFactory({
activity: { type: activityType, action: ACTIVITY_ACTIONS.CREATE },
contentType: { type: contentType, id: contentId },
});
}

const args = { contentType, activityType, contentId };

const responses = await graphqlRequest(qryActivityLogs, 'activityLogs', args);

expect(responses.length).toBe(3);

const responsesWithLimit = await graphqlRequest(qryActivityLogs, 'activityLogs', { ...args, limit: 2 });

expect(responsesWithLimit.length).toBe(2);
});
});
import * as faker from 'faker';
import { graphqlRequest } from '../db/connection';
import { activityLogFactory } from '../db/factories';
import { ActivityLogs } from '../db/models';
import { ACTIVITY_ACTIONS, ACTIVITY_CONTENT_TYPES, ACTIVITY_TYPES } from '../db/models/definitions/constants';

import './setup.ts';

describe('activityLogQueries', () => {
const commonParamDefs = `
$contentType: String!,
$contentId: String!,
$activityType: String!,
$limit: Int,
`;

const commonParams = `
contentType: $contentType
contentId: $contentId
activityType: $activityType
limit: $limit
`;

const qryActivityLogs = `
query activityLogs(${commonParamDefs}) {
activityLogs(${commonParams}) {
_id
action
id
createdAt
content
by {
type
details {
avatar
fullName
position
}
}
}
}
`;

afterEach(async () => {
// Clearing test data
await ActivityLogs.deleteMany({});
});

test('Activity log list', async () => {
const contentType = ACTIVITY_CONTENT_TYPES.CUSTOMER;
const activityType = ACTIVITY_TYPES.INTERNAL_NOTE;
const contentId = faker.random.uuid();

for (let i = 0; i < 3; i++) {
await activityLogFactory({
activity: { type: activityType, action: ACTIVITY_ACTIONS.CREATE },
contentType: { type: contentType, id: contentId },
});
}

const args = { contentType, activityType, contentId };

const responses = await graphqlRequest(qryActivityLogs, 'activityLogs', args);

expect(responses.length).toBe(3);

const responsesWithLimit = await graphqlRequest(qryActivityLogs, 'activityLogs', { ...args, limit: 2 });

expect(responsesWithLimit.length).toBe(2);
});
});
186 changes: 93 additions & 93 deletions src/__tests__/brandQueries.test.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
import { graphqlRequest } from '../db/connection';
import { brandFactory } from '../db/factories';
import { Brands } from '../db/models';

import './setup.ts';

describe('brandQueries', () => {
afterEach(async () => {
// Clearing test data
await Brands.deleteMany({});
});

test('Brands', async () => {
const args = {
page: 1,
perPage: 2,
};

await brandFactory({});
await brandFactory({});
await brandFactory({});

const qry = `
query brands($page: Int $perPage: Int) {
brands(page: $page perPage: $perPage) {
_id
name
description
code
userId
createdAt
emailConfig
integrations { _id }
}
}
`;

const response = await graphqlRequest(qry, 'brands', args);

expect(response.length).toBe(2);
});

test('Brand detail', async () => {
const qry = `
query brandDetail($_id: String!) {
brandDetail(_id: $_id) {
_id
}
}
`;

const brand = await brandFactory({});

const response = await graphqlRequest(qry, 'brandDetail', { _id: brand._id });

expect(response._id).toBe(brand._id);
});

test('Get brand total count', async () => {
const qry = `
query brandsTotalCount {
brandsTotalCount
}
`;

await brandFactory({});
await brandFactory({});
await brandFactory({});

const brandsCount = await graphqlRequest(qry, 'brandsTotalCount');

expect(brandsCount).toBe(3);
});

test('Get last brand', async () => {
const qry = `
query brandsGetLast {
brandsGetLast {
_id
}
}
`;

await brandFactory({});
await brandFactory({});

const brand = await brandFactory({});

const lastBrand = await graphqlRequest(qry, 'brandsGetLast');

expect(lastBrand._id).toBe(brand._id);
});
});
import { graphqlRequest } from '../db/connection';
import { brandFactory } from '../db/factories';
import { Brands } from '../db/models';

import './setup.ts';

describe('brandQueries', () => {
afterEach(async () => {
// Clearing test data
await Brands.deleteMany({});
});

test('Brands', async () => {
const args = {
page: 1,
perPage: 2,
};

await brandFactory({});
await brandFactory({});
await brandFactory({});

const qry = `
query brands($page: Int $perPage: Int) {
brands(page: $page perPage: $perPage) {
_id
name
description
code
userId
createdAt
emailConfig
integrations { _id }
}
}
`;

const response = await graphqlRequest(qry, 'brands', args);

expect(response.length).toBe(2);
});

test('Brand detail', async () => {
const qry = `
query brandDetail($_id: String!) {
brandDetail(_id: $_id) {
_id
}
}
`;

const brand = await brandFactory({});

const response = await graphqlRequest(qry, 'brandDetail', { _id: brand._id });

expect(response._id).toBe(brand._id);
});

test('Get brand total count', async () => {
const qry = `
query brandsTotalCount {
brandsTotalCount
}
`;

await brandFactory({});
await brandFactory({});
await brandFactory({});

const brandsCount = await graphqlRequest(qry, 'brandsTotalCount');

expect(brandsCount).toBe(3);
});

test('Get last brand', async () => {
const qry = `
query brandsGetLast {
brandsGetLast {
_id
}
}
`;

await brandFactory({});
await brandFactory({});

const brand = await brandFactory({});

const lastBrand = await graphqlRequest(qry, 'brandsGetLast');

expect(lastBrand._id).toBe(brand._id);
});
});
Loading

0 comments on commit 03f785f

Please sign in to comment.