Skip to content

Commit

Permalink
Update for 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Oct 6, 2023
1 parent 31dc4a2 commit e33556a
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 106 deletions.
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { defineConfig } = require('cypress')

module.exports = defineConfig({
env: {
url: 'http://localhost:8080',
api_url: 'http://localhost:3000',
url: 'http://localhost:8080/wizard',
api_url: 'http://localhost:3000/wizard-api',
admin_username: '[email protected]',
admin_password: 'password',
datasteward_username: '[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/settings/authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Settings / Authentication', () => {
cy.getCy('settings_authentication_service_parameter-value').type('fit.cvut.cz')

// check callback url
cy.getCy('form-group_text_callback-url').contains('http://localhost:8080/auth/google/callback')
cy.getCy('form-group_text_callback-url').contains('http://localhost:8080/wizard/auth/google/callback')

// Save and log out
cy.submitForm()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('Apps', () => {
describe('Tenants', () => {
const superAdmin = {
email: '[email protected]',
firstName: 'Galileo',
Expand All @@ -7,25 +7,25 @@ describe('Apps', () => {
password: 'Galileo\'s p455w0rd'
}

const app = {
appId: 'institution',
appName: 'My Institution',
const tenant = {
tenantId: 'institution',
tenantName: 'My Institution',
email: '[email protected]',
firstName: 'Clarice',
lastName: 'Farley'
}

const newApp = {
appId: 'university',
tenantId: 'university',
name: 'Very Nice University'
}

const createApp = () => {
cy.visitApp('/apps')
cy.visitApp('/tenants')
cy.clickBtn('Create')
cy.fillFields(app)
cy.fillFields(tenant)
cy.clickBtn('Create')
cy.getListingItem(app.appName).find('.title a').click()
cy.getListingItem(tenant.tenantName).find('.title a').click()
}

const fillPlan = (plan, trial) => {
Expand All @@ -36,20 +36,20 @@ describe('Apps', () => {
cy.uncheckToggle('test')
}
cy.clickModalAction()
cy.getCy('modal_app_plan-edit').should('not.be.visible')
cy.getCy('modal_tenant_plan-edit').should('not.be.visible')
}

const createPlan = (plan, trial, expectActive) => {
cy.getCy('app-detail_add-plan').click()
cy.getCy('tenant-detail_add-plan').click()
fillPlan(plan, trial)
}

const expectAppName = (appName) => {
cy.getCy('detail-page_header-title').contains(appName).should('exist')
const expectAppName = (tenantName) => {
cy.getCy('detail-page_header-title').contains(tenantName).should('exist')
}

const expectAppId = (appId) => {
cy.getCy('detail-page_metadata_app-id').contains(appId).should('exist')
const expectAppId = (tenantId) => {
cy.getCy('detail-page_metadata_tenant-id').contains(tenantId).should('exist')
}

const expectEnabled = () => {
Expand All @@ -76,40 +76,40 @@ describe('Apps', () => {
before(() => {
cy.task('user:delete', { email: superAdmin.email })
cy.createUser(superAdmin)
cy.task('user:addPermission', { perm: 'APP_PERM', email: superAdmin.email })
cy.task('user:addPermission', { perm: 'TENANT_PERM', email: superAdmin.email })
})


beforeEach(() => {
cy.task('app:delete', { app_id: app.appId })
cy.task('app:delete', { app_id: newApp.appId })
cy.task('tenant:delete', { tenant_id: tenant.tenantId })
cy.task('tenant:delete', { tenant_id: newApp.tenantId })
cy.loginWith(superAdmin.email, superAdmin.password)
})


after(() => {
cy.task('appLimit:reset', { uuid: '00000000-0000-0000-0000-000000000000' })
cy.task('tenantLimit:reset', { uuid: '00000000-0000-0000-0000-000000000000' })
})


it('create and edit app', () => {
// Create app
it('create and edit tenant', () => {
// Create tenant
createApp()

// Check it was created correctly
expectAppName(app.appName)
expectAppId(app.appId)
expectAppName(tenant.tenantName)
expectAppId(tenant.tenantId)
expectEnabled()

// Edit app
cy.getCy('app-detail_edit').click()
// Edit tenant
cy.getCy('tenant-detail_edit').click()
cy.fillFields(newApp)
cy.clickModalAction()
cy.getCy('modal_app-edit').should('not.be.visible')
cy.getCy('modal_tenant-edit').should('not.be.visible')

// Check it was edited correctly
expectAppName(newApp.name)
expectAppId(newApp.appId)
expectAppId(newApp.tenantId)
expectEnabled()
})

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Apps', () => {
untilMonth: '12',
untilYear: '2020',
}
cy.getCy('app-detail_plan_edit').click()
cy.getCy('tenant-detail_plan_edit').click()
fillPlan(plan2, true)
expectPlan(plan2, true, false)
expectDisabled()
Expand All @@ -216,7 +216,7 @@ describe('Apps', () => {
untilMonth: '12',
untilYear: '2070',
}
cy.getCy('app-detail_plan_edit').click()
cy.getCy('tenant-detail_plan_edit').click()
fillPlan(plan3, false)
expectPlan(plan3, false, false)
expectDisabled()
Expand All @@ -232,7 +232,7 @@ describe('Apps', () => {
untilMonth: '12',
untilYear: '2070',
}
cy.getCy('app-detail_plan_edit').click()
cy.getCy('tenant-detail_plan_edit').click()
fillPlan(plan4, false)
expectPlan(plan4, false, true)
expectEnabled()
Expand All @@ -257,9 +257,9 @@ describe('Apps', () => {
expectPlan(plan, false, true)
expectEnabled()

cy.getCy('app-detail_plan_delete').click()
cy.getCy('tenant-detail_plan_delete').click()
cy.clickModalAction()
cy.getCy('modal_app_plan-delete').should('not.be.visible')
cy.getCy('modal_tenant_plan-delete').should('not.be.visible')
expectDisabled()
})
})
129 changes: 65 additions & 64 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,67 +60,6 @@ module.exports = (on, config) => {
return pg.delete({ table: 'action_key', where })
}

// App

async function appDelete(where) {
const result = await pg.get({ table: 'app', where })
for (let i = 0; i < result.rows.length; i++) {
const { uuid } = result.rows[i]
await userDelete({ app_uuid: uuid })
await pg.delete({ table: 'action_key', where: { app_uuid: uuid } })
await pg.delete({ table: 'locale', where: { app_uuid: uuid } })
await pg.delete({ table: 'app', where: { uuid } })
}
return true
}

// App config

async function appConfigDisable2FA() {
return pg.update({
table: 'app_config',
values: {
authentication: JSON.stringify({
"defaultRole": "dataSteward",
"external": {
"services": []
},
"internal": {
"registration": {
"enabled": true
},
"twoFactorAuth": {
"codeLength": 6,
"enabled": false,
"expiration": 600
}
}
})
}
})
}

// App limits

async function appLimitReset(where) {
return pg.update({
table: 'app_limit',
values: {
active_users: null,
branches: null,
document_template_drafts: null,
document_templates: null,
documents: null,
knowledge_models: null,
locales: null,
questionnaires: null,
storage: null,
users: null,
},
where
})
}

// Branch

async function branchDelete(where) {
Expand Down Expand Up @@ -231,6 +170,68 @@ module.exports = (on, config) => {
return true
}

// Tenant

async function tenantDelete(where) {
const result = await pg.get({ table: 'tenant', where })
for (let i = 0; i < result.rows.length; i++) {
const { uuid } = result.rows[i]
await userDelete({ tenant_uuid: uuid })
await pg.delete({ table: 'action_key', where: { tenant_uuid: uuid } })
await pg.delete({ table: 'locale', where: { tenant_uuid: uuid } })
await pg.delete({ table: 'tenant_plan', where: { tenant_uuid: uuid } })
await pg.delete({ table: 'tenant', where: { uuid } })
}
return true
}

// Tenant config

async function tenantConfigDisable2FA() {
return pg.update({
table: 'tenant_config',
values: {
authentication: JSON.stringify({
'defaultRole': 'dataSteward',
'external': {
'services': []
},
'internal': {
'registration': {
'enabled': true
},
'twoFactorAuth': {
'codeLength': 6,
'enabled': false,
'expiration': 600
}
}
})
}
})
}


// Tenant limits

async function tenantLimitReset(where) {
return pg.update({
table: 'tenant_limit_bundle',
values: {
active_users: null,
branches: null,
document_template_drafts: null,
document_templates: null,
documents: null,
knowledge_models: null,
locales: null,
questionnaires: null,
storage: null,
users: null,
},
where
})
}

// User

Expand Down Expand Up @@ -267,9 +268,6 @@ module.exports = (on, config) => {

on('task', {
'actionKey:delete': actionKeyDelete,
'app:delete': appDelete,
'appConfig:disable2FA': appConfigDisable2FA,
'appLimit:reset': appLimitReset,
'branch:delete': branchDelete,
'document:delete': documentDelete,
'documentTemplate:delete': documentTemplateDelete,
Expand All @@ -279,6 +277,9 @@ module.exports = (on, config) => {
'package:get': packageGet,
'package:setNonEditable': packageSetNonEditable,
'questionnaire:delete': questionnaireDelete,
'tenant:delete': tenantDelete,
'tenantConfig:disable2FA': tenantConfigDisable2FA,
'tenantLimit:reset': tenantLimitReset,
'user:activate': userActivate,
'user:getActionParams': userGetActionParams,
'user:delete': userDelete,
Expand Down
8 changes: 4 additions & 4 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const login = (resp, expiresAt = null) => {

const createSession = (token, user, expiresAt = null) => {
expiresAt = expiresAt || new Date(Date.now() + 14000 * 86400)
window.localStorage.setItem('session', JSON.stringify({
window.localStorage.setItem('session/wizard', JSON.stringify({
sidebarCollapsed: false,
token: { token, expiresAt },
user,
Expand All @@ -50,7 +50,7 @@ Cypress.Commands.add('loginWith', (email, password) => {
})

Cypress.Commands.add('logout', () => {
window.localStorage.removeItem('session')
window.localStorage.removeItem('session/wizard')
cy.visitApp('/')
})

Expand Down Expand Up @@ -393,12 +393,12 @@ Cypress.Commands.add('expectToggleUnchecked', (field) => {
// Settings commands

Cypress.Commands.add('putDefaultAppConfig', () => {
cy.task('appConfig:disable2FA')
cy.task('tenantConfig:disable2FA')
getTokenFor('admin').then((resp) => {
cy.fixture('default-app-config').then((config) => {
cy.request({
method: 'PUT',
url: apiUrl('/configs/app'),
url: apiUrl('/tenants/current/config'),
headers: createHeaders(resp.body.token),
body: config
})
Expand Down
2 changes: 1 addition & 1 deletion dsw/docker-compose.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
ports:
- 8080:8080
environment:
API_URL: http://localhost:3000
API_URL: http://localhost:3000/wizard-api

docworker:
platform: linux/amd64
Expand Down
2 changes: 1 addition & 1 deletion dsw/server/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
general:
environment: Production
serverPort: 3000
clientUrl: http://localhost:8080
clientUrl: http://localhost:8080/wizard
secret: ab012345678901234567890123456789
rsaPrivateKey: |
-----BEGIN RSA PRIVATE KEY-----
Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -e

# Docker Images
SERVER_IMAGE="${SERVER_IMAGE:-dswbot/wizard-server:develop}"
CLIENT_IMAGE="${CLIENT_IMAGE:-dswbot/wizard-client:develop}"
SERVER_IMAGE="${SERVER_IMAGE:-dswbot/wizard-server:next-develop}"
CLIENT_IMAGE="${CLIENT_IMAGE:-dswbot/wizard-client:develop-next}"
DOCWORKER_IMAGE="${DOCWORKER_IMAGE:-dswbot/document-worker:develop}"

cd dsw
Expand Down

0 comments on commit e33556a

Please sign in to comment.