This repository has been archived by the owner on Nov 21, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permission): restrict user permissions by brand
close #517
- Loading branch information
Showing
113 changed files
with
5,047 additions
and
4,911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ PORT_CRONS=3600 | |
|
||
# workers | ||
PORT_WORKERS=3700 | ||
|
||
USE_BRAND_RESTRICTIONS=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.