Last active
September 9, 2023 23:48
-
-
Save oimtrust/2b08c639232509155c311e41f214774e to your computer and use it in GitHub Desktop.
Add Sleep and skip test on mochaJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chai, { expect } from "chai"; | |
import jsonSchema from "chai-json-schema"; | |
import * as data from "$digital-product/data/digital-product/get-postpaid-information.data"; | |
import digitalProductAPI from "$digital-product/pages/v2/digital-product.api"; | |
import * as schema from "$digital-product/schema/digital-product/get-postpaid-information.schema"; | |
import * as api from "$digital-product/helper/lib-api"; | |
import * as login from "$digital-product/data/users/login.data"; | |
import util from 'util'; | |
chai.use(jsonSchema); | |
const assert = chai.assert; | |
const sleep = util.promisify(setTimeout); | |
describe("@automation-test-pipeline Digital Product - Get Inquiry of Postpaid Electricity", () => { | |
let token; | |
beforeEach(async() => { | |
token = await api.getToken(login.VALID_LOGIN_DIGITAL_PRODUCT_GENERAL); | |
await sleep(20000); | |
}); | |
it("C246687 - Execute API call with unpaid electricity bill parameter", async () => { | |
const getData = api.getParams(data.PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
assert.equal(response.status, 200); | |
expect(response.data).to.be.jsonSchema( | |
schema.GET_POSTPAID_INFORMATION_SCHEMA | |
); | |
}); | |
it('C246689 - Execute API call with paid electricity bill parameter', async () => { | |
const getData = api.getParams(data.PAID_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.PAID_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.PAID_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it('C246690 - Execute API call with timeout from provider parameter', async () => { | |
const getData = api.getParams(data.FAILED_INQUIRY_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.FAILED_INQUIRY_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.FAILED_INQUIRY_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it('C246691 - Execute API call with invalid customer number parameter', async () => { | |
const getData = api.getParams(data.ACCOUNT_NUMBER_NOT_FOUND_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.ACCOUNT_NUMBER_NOT_FOUND_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.ACCOUNT_NUMBER_NOT_FOUND_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it('C246692 - Execute API call with billing is not available yet parameter', async () => { | |
const getData = api.getParams(data.NO_AVAILABLE_BILL_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.NO_AVAILABLE_BILL_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.NO_AVAILABLE_BILL_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it('C246693 - Execute API call with billing of that month is not available yet parameter', async () => { | |
const getData = api.getParams(data.NO_AVAILABLE_BILL_THIS_MONTH_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.NO_AVAILABLE_BILL_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.NO_AVAILABLE_BILL_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it('C246694 - Execute API call with blocked account parameter', async () => { | |
const getData = api.getParams(data.BLOCKED_ACCOUNT_PARAMS); | |
const accountNumber = getData.get("account_number"); | |
const productCode = getData.get("product_code"); | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.BLOCKED_ACCOUNT_RESPONSE.code) | |
assert.equal(response.data.errors[0].message, data.BLOCKED_ACCOUNT_RESPONSE.message) | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
it("C252176 - Execute API call with invalid parameter", async () => { | |
const accountNumber = null; | |
const productCode = null; | |
const response = await digitalProductAPI.getPostpaidInformation( | |
accountNumber, | |
productCode, | |
token | |
); | |
if (response.status === 422) { | |
assert.equal(response.status, 422); | |
assert.equal(response.data.errors[0].code, data.INVALID_RESPONSE.code); | |
assert.equal( | |
response.data.errors[0].message, | |
data.INVALID_RESPONSE.message | |
); | |
expect(response.data).to.be.jsonSchema( | |
schema.ERROR_MESSAGE_SCHEMA | |
); | |
} else { | |
this.skip(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment