Skip to content
Snippets Groups Projects
Commit c89bf90e authored by Yannis Barlas's avatar Yannis Barlas
Browse files

feat(*): make teams configs arrays

BREAKING CHANGE:
changed teams config structure
parent 38f4a112
No related branches found
No related tags found
1 merge request!123v4
......@@ -3,34 +3,34 @@ const components = require('./components')
module.exports = {
components,
teams: {
global: {
admin: {
global: [
{
displayName: 'Admin',
role: 'admin',
},
editor: {
{
displayName: 'Editor',
role: 'editor',
},
author: {
{
displayName: 'Author',
role: 'author',
},
},
nonGlobal: {
editor: {
],
nonGlobal: [
{
displayName: 'Editor',
role: 'editor',
},
author: {
{
displayName: 'Author',
role: 'author',
},
reviewer: {
{
displayName: 'Reviewer',
role: 'reviewer',
},
},
],
},
host: 'localhost',
useFileStorage: true,
......
module.exports = {
logger: {
logger: {
info: () => {},
error: () => {},
debug: () => {},
warn: () => {},
},
info: () => {},
error: () => {},
debug: () => {},
warn: () => {},
},
}
......@@ -2,6 +2,7 @@ module.exports = {
collectCoverage: false,
maxWorkers: 1,
globalSetup: '<rootDir>/src/models/__tests__/_setup.js',
globalTeardown: '<rootDir>/src/models/__tests__/_teardown.js',
testEnvironment: 'node',
testRegex: '(/src/.*\\.test\\.js$|/__tests__/.*\\.test\\.js$)',
}
......@@ -19,7 +19,7 @@
"cz": "./node_modules/.bin/git-cz",
"prepare": "husky install",
"release": "standard-version",
"test": "NODE_ENV=test ALLOW_CONFIG_MUTATIONS=1 docker compose run server yarn jest --verbose"
"test": "NODE_ENV=test ALLOW_CONFIG_MUTATIONS=1 yarn jest --verbose"
},
"husky": {
"hooks": {
......
......@@ -12,7 +12,7 @@ const dbCleaner = async () => {
rows.map(async row => {
const { tablename } = row
if (tablename !== 'migrations') {
if (!['migrations', 'coko_server_meta'].includes(tablename)) {
await db.raw(`TRUNCATE TABLE ${tablename} CASCADE`)
}
......
const db = require('../../dbManager/db')
module.exports = async () => {
db.destroy()
await db.destroy()
}
const createTestServer = require('./helpers/createTestServer')
const { Team, TeamMember, User } = require('..')
const db = require('../../dbManager/db')
const clearDb = require('./_clearDb')
describe('Team API', () => {
beforeEach(() => clearDb())
beforeEach(async () => {
await clearDb()
})
afterAll(() => {
const knex = Team.knex()
knex.destroy()
afterAll(async () => {
await db.destroy()
})
it('returns global teams with members', async () => {
......
const config = require('config')
const union = require('lodash/union')
const globalTeams = Object.values(
(config.has('teams.global') && config.get('teams.global')) || {},
)
const globalTeams =
(config.has('teams.global') && config.get('teams.global')) || []
const nonGlobalTeams = Object.values(
(config.has('teams.nonGlobal') && config.get('teams.nonGlobal')) || {},
)
const nonGlobalTeams =
(config.has('teams.nonGlobal') && config.get('teams.nonGlobal')) || []
const allTeams = union(globalTeams, nonGlobalTeams)
......
......@@ -16,31 +16,29 @@ const seedGlobalTeams = async () => {
await useTransaction(async trx => {
await Promise.all(
Object.keys(configGlobalTeams).map(async k => {
const teamData = configGlobalTeams[k]
configGlobalTeams.map(async t => {
const exists = await Team.findOne(
{
global: true,
role: teamData.role,
role: t.role,
},
{ trx },
)
if (exists) {
logTaskItem(`Global team "${teamData.role}" already exists`)
logTaskItem(`Global team "${t.role}" already exists`)
return
}
await Team.insert(
{
...teamData,
...t,
global: true,
},
{ trx },
)
logTaskItem(`Added global team "${teamData.role}"`)
logTaskItem(`Added global team "${t.role}"`)
}),
)
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment