Merge pull request #7 from opdavies/api-client-tests

Add ApiClient tests
This commit is contained in:
Oliver Davies 2019-04-09 18:22:29 +01:00 committed by GitHub
commit 1844d0d627
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 2209 additions and 274 deletions

View 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)
})
})

View file

@ -1,5 +1,12 @@
module.exports = {
presets: [
'@vue/app'
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
}

View file

@ -1,4 +1,4 @@
[build]
command = "yarn build"
command = "yarn test && yarn build"
publish = "dist"
environment = { YARN_VERSION = "1.13.0" }

View file

@ -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"
}
}

View file

@ -1,257 +1,17 @@
import _ from 'lodash'
const data = {
types: {
drupal: {
id: 'drupal',
name: 'Drupal'
},
nodejs: {
id: 'nodejs',
name: 'Node.js'
}
},
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: '7.1'
}
},
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.1'
}
},
ra: {
name: 'RA',
url: 'ra.rebuilding-acquia.com',
label: 'tags/WELCOME',
versions: {
php: '7.2'
}
}
},
tasks: [
{
text: 'Commit: fdac923 Merge branch \'update-password-policy\' refs/heads/master',
user: 'system',
times: {
display: 'Dec 19, 2018 3:48:29 PM UTC +0000',
started: 'Dec 19, 2018 3:48:29 PM UTC +0000',
completed: 'Dec 19, 2018 3:48:29 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 9688c41 Update IP address refs/heads/master',
user: 'system',
times: {
display: 'Dec 19, 2018 3:50:31 PM UTC +0000',
started: 'Dec 19, 2018 3:50:31 PM UTC +0000',
completed: 'Dec 19, 2018 3:50:31 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy code from test to prod',
user: 'system',
times: {
display: 'Dec 19, 2018 3:55:29 PM UTC +0000',
started: 'Dec 19, 2018 3:55:29 PM UTC +0000',
completed: 'Dec 19, 2018 3:55:29 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy the code reference master to dev',
user: 'system',
times: {
display: 'Dec 20, 2018 10:13:48 PM UTC +0000',
started: 'Dec 20, 2018 10:13:48 PM UTC +0000',
completed: 'Dec 20, 2018 10:13:48 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy the code reference tags/2018-12-19 to test',
user: 'system',
times: {
display: 'Dec 20, 2018 10:25:07 PM UTC +0000',
started: 'Dec 20, 2018 10:25:07 PM UTC +0000',
completed: 'Dec 20, 2018 10:25:07 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: e75c4a3 Merge branch \'voucher-code-bug-34\' refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 12:55:49 PM UTC +0000',
started: 'Dec 21, 2018 12:55:49 PM UTC +0000',
completed: 'Dec 21, 2018 12:55:49 PM UTC +0000'
},
status: 'Failed',
loading: false,
success: false
},
{
text: 'Commit: 398945c Ensure stage_file_proxy is enabled refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:09:19 PM UTC +0000',
started: 'Dec 21, 2018 1:09:19 PM UTC +0000',
completed: 'Dec 21, 2018 1:09:19 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 96ac151 Fix syntax refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:23:43 PM UTC +0000',
started: 'Dec 21, 2018 1:23:43 PM UTC +0000',
completed: 'Dec 21, 2018 1:23:43 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 8056d51 Add production URLs as settings refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:34:13 PM UTC +0000',
started: 'Dec 21, 2018 1:34:13 PM UTC +0000',
completed: 'Dec 21, 2018 1:34:13 PM UTC +0000'
},
status: 'In progress',
loading: true,
success: true
}
]
},
2: {
id: 2,
name: 'Oliver Davies',
machineName: 'oliverdavies',
type: 'drupal',
level: 'Professional',
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: [
{
text: 'Create database opdaviestest in Dev.',
user: 'system',
times: {
display: 'Dec 23, 2018 11:26:48 PM UTC +0000',
started: 'Dec 23, 2018 11:26:50 PM UTC +0000',
completed: 'Dec 23, 2018 11:26:52 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Create database opdaviestest in Stage.',
user: 'system',
times: {
display: 'Dec 23, 2018 11:26:48 PM UTC +0000',
started: 'Dec 23, 2018 11:26:50 PM UTC +0000',
completed: 'Dec 23, 2018 11:26:52 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Install Drupal 8 to Dev.',
user: 'oliver@oliverdavies.uk (oliver@oliverdavies.uk)',
times: {
display: 'Dec 23, 2018 11:33:52 PM UTC +0000',
started: 'Dec 23, 2018 11:33:53 PM UTC +0000',
completed: 'Dec 23, 2018 11:37:21 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 9736ef5 Importing site archive refs/heads/master',
user: 'vcs.commit',
times: {
display: 'Dec 23, 2018 11:36:29 PM UTC +0000',
started: 'Dec 23, 2018 11:36:30 PM UTC +0000',
completed: 'Dec 23, 2018 11:37:16 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 0ab620f Initial commit to Acquia Git starter repo. refs/tags/pre-import-2018-12-23',
user: 'vcs.commit',
times: {
display: 'Dec 23, 2018 11:36:30 PM UTC +0000',
started: 'Dec 23, 2018 11:36:32 PM UTC +0000',
completed: 'Dec 23, 2018 11:36:33 PM UTC +0000'
},
loading: false,
success: true
}
]
}
}
}
let data = require('./data').default
export default {
methods: {
setData (newData) {
data = newData
},
getData () {
return data
},
getTypes () {
return data.types
},

249
src/data.js Normal file
View file

@ -0,0 +1,249 @@
export default {
types: {
drupal: {
id: 'drupal',
name: 'Drupal'
},
nodejs: {
id: 'nodejs',
name: 'Node.js'
}
},
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: '7.1'
}
},
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.1'
}
},
ra: {
name: 'RA',
url: 'ra.rebuilding-acquia.com',
label: 'tags/WELCOME',
versions: {
php: '7.2'
}
}
},
tasks: [
{
text: 'Commit: fdac923 Merge branch \'update-password-policy\' refs/heads/master',
user: 'system',
times: {
display: 'Dec 19, 2018 3:48:29 PM UTC +0000',
started: 'Dec 19, 2018 3:48:29 PM UTC +0000',
completed: 'Dec 19, 2018 3:48:29 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 9688c41 Update IP address refs/heads/master',
user: 'system',
times: {
display: 'Dec 19, 2018 3:50:31 PM UTC +0000',
started: 'Dec 19, 2018 3:50:31 PM UTC +0000',
completed: 'Dec 19, 2018 3:50:31 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy code from test to prod',
user: 'system',
times: {
display: 'Dec 19, 2018 3:55:29 PM UTC +0000',
started: 'Dec 19, 2018 3:55:29 PM UTC +0000',
completed: 'Dec 19, 2018 3:55:29 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy the code reference master to dev',
user: 'system',
times: {
display: 'Dec 20, 2018 10:13:48 PM UTC +0000',
started: 'Dec 20, 2018 10:13:48 PM UTC +0000',
completed: 'Dec 20, 2018 10:13:48 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Deploy the code reference tags/2018-12-19 to test',
user: 'system',
times: {
display: 'Dec 20, 2018 10:25:07 PM UTC +0000',
started: 'Dec 20, 2018 10:25:07 PM UTC +0000',
completed: 'Dec 20, 2018 10:25:07 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: e75c4a3 Merge branch \'voucher-code-bug-34\' refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 12:55:49 PM UTC +0000',
started: 'Dec 21, 2018 12:55:49 PM UTC +0000',
completed: 'Dec 21, 2018 12:55:49 PM UTC +0000'
},
status: 'Failed',
loading: false,
success: false
},
{
text: 'Commit: 398945c Ensure stage_file_proxy is enabled refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:09:19 PM UTC +0000',
started: 'Dec 21, 2018 1:09:19 PM UTC +0000',
completed: 'Dec 21, 2018 1:09:19 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 96ac151 Fix syntax refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:23:43 PM UTC +0000',
started: 'Dec 21, 2018 1:23:43 PM UTC +0000',
completed: 'Dec 21, 2018 1:23:43 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 8056d51 Add production URLs as settings refs/heads/master',
user: 'system',
times: {
display: 'Dec 21, 2018 1:34:13 PM UTC +0000',
started: 'Dec 21, 2018 1:34:13 PM UTC +0000',
completed: 'Dec 21, 2018 1:34:13 PM UTC +0000'
},
status: 'In progress',
loading: true,
success: true
}
]
},
2: {
id: 2,
name: 'Oliver Davies',
machineName: 'oliverdavies',
type: 'drupal',
level: 'Professional',
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: [
{
text: 'Create database opdaviestest in Dev.',
user: 'system',
times: {
display: 'Dec 23, 2018 11:26:48 PM UTC +0000',
started: 'Dec 23, 2018 11:26:50 PM UTC +0000',
completed: 'Dec 23, 2018 11:26:52 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Create database opdaviestest in Stage.',
user: 'system',
times: {
display: 'Dec 23, 2018 11:26:48 PM UTC +0000',
started: 'Dec 23, 2018 11:26:50 PM UTC +0000',
completed: 'Dec 23, 2018 11:26:52 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Install Drupal 8 to Dev.',
user: 'oliver@oliverdavies.uk (oliver@oliverdavies.uk)',
times: {
display: 'Dec 23, 2018 11:33:52 PM UTC +0000',
started: 'Dec 23, 2018 11:33:53 PM UTC +0000',
completed: 'Dec 23, 2018 11:37:21 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 9736ef5 Importing site archive refs/heads/master',
user: 'vcs.commit',
times: {
display: 'Dec 23, 2018 11:36:29 PM UTC +0000',
started: 'Dec 23, 2018 11:36:30 PM UTC +0000',
completed: 'Dec 23, 2018 11:37:16 PM UTC +0000'
},
loading: false,
success: true
},
{
text: 'Commit: 0ab620f Initial commit to Acquia Git starter repo. refs/tags/pre-import-2018-12-23',
user: 'vcs.commit',
times: {
display: 'Dec 23, 2018 11:36:30 PM UTC +0000',
started: 'Dec 23, 2018 11:36:32 PM UTC +0000',
completed: 'Dec 23, 2018 11:36:33 PM UTC +0000'
},
loading: false,
success: true
}
]
}
}
}

1743
yarn.lock

File diff suppressed because it is too large Load diff