parent
5c74425d67
commit
201dcb4e92
215
__tests__/api_client.test.js
Normal file
215
__tests__/api_client.test.js
Normal file
|
@ -0,0 +1,215 @@
|
|||
import _ from 'lodash'
|
||||
|
||||
const apiClient = require('../src/api-client')
|
||||
const methods = apiClient.default.methods
|
||||
|
||||
test('it can get the application types', () => {
|
||||
const data = {
|
||||
types: {
|
||||
drupal: {
|
||||
id: 'drupal',
|
||||
name: 'Drupal'
|
||||
},
|
||||
symfony: {
|
||||
id: 'symfony',
|
||||
name: 'Symfony'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
expect(methods.getTypes()).toBe(data.types)
|
||||
})
|
||||
|
||||
test('it can get the applications', () => {
|
||||
const data = {
|
||||
applications: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: 'Rebuilding Acquia',
|
||||
machineName: 'rebuildingacquia',
|
||||
type: 'drupal',
|
||||
level: 'Enterprise',
|
||||
environments: {},
|
||||
tasks: {}
|
||||
},
|
||||
2: {
|
||||
id: 2,
|
||||
name: 'Oliver Davies',
|
||||
machineName: 'oliverdavies',
|
||||
type: 'drupal',
|
||||
level: 'Professional',
|
||||
environments: {},
|
||||
tasks: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
expect(methods.getApplications()).toBe(data.applications)
|
||||
})
|
||||
|
||||
test('it can get a single application', () => {
|
||||
const data = {
|
||||
applications: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: 'Rebuilding Acquia',
|
||||
machineName: 'rebuildingacquia',
|
||||
type: 'drupal',
|
||||
level: 'Enterprise',
|
||||
environments: {},
|
||||
tasks: {}
|
||||
},
|
||||
2: {
|
||||
id: 2,
|
||||
name: 'Oliver Davies',
|
||||
machineName: 'oliverdavies',
|
||||
type: 'drupal',
|
||||
level: 'Professional',
|
||||
environments: {},
|
||||
tasks: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
_.forEach([1, 2], (applicationId) => {
|
||||
expect(methods.getApplication(applicationId))
|
||||
.toBe(data.applications[applicationId])
|
||||
})
|
||||
})
|
||||
|
||||
test('it can get an environment for an application', () => {
|
||||
const data = {
|
||||
applications: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: 'Rebuilding Acquia',
|
||||
machineName: 'rebuildingacquia',
|
||||
type: 'drupal',
|
||||
level: 'Enterprise',
|
||||
environments: {
|
||||
dev: {
|
||||
name: 'Dev',
|
||||
url: 'dev.oliverdavies.uk',
|
||||
label: 'develop',
|
||||
versions: {
|
||||
php: '7.2'
|
||||
}
|
||||
},
|
||||
stage: {
|
||||
name: 'Stage',
|
||||
url: 'stg.oliverdavies.uk',
|
||||
label: 'master',
|
||||
versions: {
|
||||
php: '7.2'
|
||||
}
|
||||
},
|
||||
prod: {
|
||||
name: 'Prod',
|
||||
url: 'oliverdavies.uk',
|
||||
label: 'tags/2018-12-21',
|
||||
versions: {
|
||||
php: '7.2'
|
||||
}
|
||||
},
|
||||
tasks: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
_.forEach(['dev', 'stage', 'prod'], (environmentName) => {
|
||||
expect(methods.getEnvironment(1, environmentName))
|
||||
.toBe(data.applications[1].environments[environmentName])
|
||||
})
|
||||
})
|
||||
|
||||
test('it can get the type of an application', () => {
|
||||
const data = {
|
||||
types: {
|
||||
drupal: {
|
||||
id: 'drupal',
|
||||
name: 'Drupal'
|
||||
},
|
||||
symfony: {
|
||||
id: 'symfony',
|
||||
name: 'Symfony'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
const applications = {
|
||||
drupal: {
|
||||
type: 'drupal'
|
||||
},
|
||||
symfony: {
|
||||
type: 'symfony'
|
||||
},
|
||||
}
|
||||
|
||||
_.forEach(applications, (application, expected) => {
|
||||
expect(methods.getApplicationType(application)).toBe(data.types[expected])
|
||||
})
|
||||
})
|
||||
|
||||
test('it can get a version from an environment', () => {
|
||||
const data = {
|
||||
applications: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: 'Rebuilding Acquia',
|
||||
machineName: 'rebuildingacquia',
|
||||
type: 'drupal',
|
||||
level: 'Enterprise',
|
||||
environments: {
|
||||
dev: {
|
||||
name: 'Dev',
|
||||
url: 'dev.rebuilding-acquia.com',
|
||||
label: 'develop',
|
||||
versions: {
|
||||
php: '5.6'
|
||||
}
|
||||
},
|
||||
stage: {
|
||||
name: 'Stage',
|
||||
url: 'stg.rebuilding-acquia.com',
|
||||
label: 'master',
|
||||
versions: {
|
||||
php: '7.1'
|
||||
}
|
||||
},
|
||||
prod: {
|
||||
name: 'Prod',
|
||||
url: 'rebuilding-acquia.com',
|
||||
label: 'tags/2018-12-21',
|
||||
versions: {
|
||||
php: '7.2'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.setData(data)
|
||||
|
||||
const expected = {
|
||||
dev: '5.6',
|
||||
stage: '7.1',
|
||||
prod: '7.2'
|
||||
}
|
||||
|
||||
_.forEach(expected, (version, environment) => {
|
||||
expect(methods.getVersion('php', data.applications[1].environments[environment]))
|
||||
.toBe(version)
|
||||
})
|
||||
})
|
|
@ -1,5 +1,12 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
'@vue/app'
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {
|
||||
node: 'current'
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint"
|
||||
"lint": "vue-cli-service lint",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"postcss-nested": "^4.1.2",
|
||||
|
@ -16,13 +17,17 @@
|
|||
"vue-router": "^3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.4.3",
|
||||
"@babel/preset-env": "^7.4.3",
|
||||
"@vue/cli-plugin-babel": "^3.5.1",
|
||||
"@vue/cli-plugin-eslint": "^3.5.1",
|
||||
"@vue/cli-service": "^3.5.1",
|
||||
"@vue/eslint-config-standard": "^4.0.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-jest": "^24.7.1",
|
||||
"eslint": "^5.8.0",
|
||||
"eslint-plugin-vue": "^5.0.0",
|
||||
"jest": "^24.7.1",
|
||||
"vue-template-compiler": "^2.5.21"
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue