From 29e5d0821081dc57df2619b512e7ffd632783bf6 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 1 Jun 2022 13:34:20 +0800 Subject: [PATCH] Refactored Admin API test agent to use async/await no issue - Improves readability of what's going on in the code. --- test/utils/admin-api-test-agent.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/test/utils/admin-api-test-agent.js b/test/utils/admin-api-test-agent.js index d8b26b0252..6589fb4c7b 100644 --- a/test/utils/admin-api-test-agent.js +++ b/test/utils/admin-api-test-agent.js @@ -20,26 +20,25 @@ class AdminAPITestAgent extends TestAgent { } async loginAs(email, password) { - await this.post('/session/') + const res = await this.post('/session/') .body({ grant_type: 'password', username: email, password: password - }) - .then(function then(res) { - if (res.statusCode === 302) { - // This can happen if you already have an instance running e.g. if you've been using Ghost CLI recently - throw new errors.IncorrectUsageError({ - message: 'Ghost is redirecting, do you have an instance already running on port 2369?' - }); - } else if (res.statusCode !== 200 && res.statusCode !== 201) { - throw new errors.IncorrectUsageError({ - message: res.body.errors[0].message - }); - } - - return res.headers['set-cookie']; }); + + if (res.statusCode === 302) { + // This can happen if you already have an instance running e.g. if you've been using Ghost CLI recently + throw new errors.IncorrectUsageError({ + message: 'Ghost is redirecting, do you have an instance already running on port 2369?' + }); + } else if (res.statusCode !== 200 && res.statusCode !== 201) { + throw new errors.IncorrectUsageError({ + message: res.body.errors[0].message + }); + } + + return res.headers['set-cookie']; } async loginAsOwner() {