using axios
npm i axios --save
using axios
const axios = require('axios')
axios
.get('https://www.egencia.com/flight-service/base/version')
.then(response => {
console.log(response.data)
})
using axios
const axios = require('axios')
axios
.post('http://localhost:3000/services', {
env: 'maui',
service_name: 'flight-service',
})
.then(response => {
console.log(response.data)
})
docker run -p 27017:27017 mongo:latest
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/database', {
useNewUrlParser: true,
})
const baseVersionSchema = new mongoose.Schema({
service_name: String,
build_version: String,
})
const BaseVersionModel = mongoose.model('BaseVersion', baseVersionSchema)
const baseVersion = new BaseVersionModel({
service_name: 'flight-service',
build_version: '2019',
})
baseVersion.save().then(() => {
console.log('saved')
})
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/database', {
useNewUrlParser: true,
})
const baseVersionSchema = new mongoose.Schema({
service_name: String,
build_version: String,
})
const BaseVersionModel = mongoose.model('BaseVersion', baseVersionSchema)
BaseVersionModel.find()
.lean() // necessary for json output
.then(data => {
console.log(data)
})
npm i --save-dev jest supertest
npm i --save-dev eslint-plugin-jest
install dependencies
// in package.json add this section
"jest": {
"testEnvironment": "node"
}
// in .eslintrc.js, add plugins:
'plugin:jest/recommended'
configure jest
const app = require('../src/app')
const request = require('supertest')
it('should return hello world', async function() {
const response = await request(app).get('/hello-world')
expect(response.text).toEqual('hello world')
})
helloworld
npm install mongodb-memory-server --save-dev
const { MongoMemoryServer } = require('mongodb-memory-server')
const app = require('../../src/app')
const request = require('supertest')
const mongoose = require('mongoose')
let mongod
beforeEach(async () => {
mongod = new MongoMemoryServer()
const uri = await mongod.getConnectionString()
await mongoose.connect(uri)
})
afterEach(async () => {
mongod.stop()
})
npm install nock --save-dev
nock('https://www.egencia.com')
.get('/flight-service/base/version')
.reply(200, {
application_name: 'flight-service',
active_profiles: 'prod,prodch,ancillaries,oms',
stage: 'prod',
machine_name: 'chexjvgect004',
application_data: {
step_bom_version: '8.6.2',
},
build_version: '2019-05-27-15-15-94093f32a',
build_number: '94093f32a449b31104c7c2767ee5fd2a42447b99',
build_date: '2019-05-27T15:17:025Z',
})
.persist()