Skip to content

Instantly share code, notes, and snippets.

@udomsak
Created May 27, 2018 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udomsak/d5992b3c231da41b6186b35c1a8cebb4 to your computer and use it in GitHub Desktop.
Save udomsak/d5992b3c231da41b6186b35c1a8cebb4 to your computer and use it in GitHub Desktop.
//Define variable before init ActionHero SpecHelper
api.config.upload_config.storage_path = 'c:\\tmp'
// Run API
let {fileUpLoad} = await api.specHelper.runAction('SuperFileUpload')
// Run Async/Awaith Test API
await chai.request('http://localhost:' + api.config.servers.web.port)
// API end point
/* res.body return JSON object from an API
* define object or key-value you want to check ( property and value )
* returnValue = check return value as expect
* hidden_form_value_or_another = field/value that i want send to API couple with file upload
* */
.post('/api/superfileupload')
.field('hidden_form_value_or_another', 'my_hidden_value')
// Read attachment file ( test.png )
.attach('File', fs.readFileSync('./test/asset/test.png'), 'test.png')
.then(function (res) {
var checkJsonResponseReturn = {
'hidden_form_value_or_another': 'my_hidden_value'
}
// Make sure attribute that from response must have.
expect(res.body).to.have.property('hidden_form_value_or_another')
// Check that service operate correctly with both key and value that we expect with value define above
expect(res.body).to.deep.include(checkJsonResponseReturn)
// Check service API must return 200 if their operate normal
expect(res).to.have.status(200)
})
.catch(function (err) {
throw err
})
expect(superfileupload)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment