Add ApiClient tests

Fixes #4
This commit is contained in:
Oliver Davies 2019-04-09 18:12:31 +01:00
parent 5c74425d67
commit 201dcb4e92
4 changed files with 1950 additions and 24 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 = { module.exports = {
presets: [ presets: [
'@vue/app' [
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
] ]
} }

View file

@ -5,7 +5,8 @@
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint",
"test": "jest"
}, },
"dependencies": { "dependencies": {
"postcss-nested": "^4.1.2", "postcss-nested": "^4.1.2",
@ -16,13 +17,17 @@
"vue-router": "^3.0.2" "vue-router": "^3.0.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@vue/cli-plugin-babel": "^3.5.1", "@vue/cli-plugin-babel": "^3.5.1",
"@vue/cli-plugin-eslint": "^3.5.1", "@vue/cli-plugin-eslint": "^3.5.1",
"@vue/cli-service": "^3.5.1", "@vue/cli-service": "^3.5.1",
"@vue/eslint-config-standard": "^4.0.0", "@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^10.0.1", "babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"eslint": "^5.8.0", "eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0", "eslint-plugin-vue": "^5.0.0",
"jest": "^24.7.1",
"vue-template-compiler": "^2.5.21" "vue-template-compiler": "^2.5.21"
} }
} }

1743
yarn.lock

File diff suppressed because it is too large Load diff