Friday 9 June 2017

Cannot extract resolved object from Returned Promise

For some reason, no matter what I do (tweaking my code here which I'm obviously missing something I can't see), for this line in my test:

let { failure, success, payload } = await Deploy.createBucket(options)

Test

it.only('can create a new S3 bucket', async () => {
      const options = { branch: '11' }
      let { failure, success, payload } = await Deploy.createBucket(options)

      expect(payload).to.exist
      expect(payload.location).to.equal(`http://oursite-${options.branch}.s3.amazonaws.com/`)
})

Implementation

export async function createBucket (options){

  try {
    let {error, stdout, stderr} = exec(`aws s3api create-bucket --bucket oursite-${options.branch} --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2`)
    const results  = JSON.parse(stdout) || null

    if (results) {
      return new Promise((resolve) => {
        resolve({
          failure: {},
          success: true,
          payload: results
        })
      })
    }
    return new Promise((resolve) => {
      resolve({
        failure: {},
        success: {},
        payload: {}
      })
    })
  }
  catch(err) {
     //TODO: do something with this
  }
}



via PositiveGuy

No comments:

Post a Comment