This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
/
deleteCouponIT.js
122 lines (105 loc) · 4.71 KB
/
deleteCouponIT.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
*
* Copyright 2018 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
'use strict';
const chai = require('chai');
const chaiHttp = require('chai-http');
const HttpStatus = require('http-status-codes');
const setup = require('../lib/setupIT.js').setup;
const expect = chai.expect;
const requiredFields = require('../lib/requiredFields');
chai.use(chaiHttp);
/**
* For this test to pass a coupon with code coupon10 should be configured in Magento.
*/
describe('magento deleteCoupon', function () {
describe('Integration tests', function () {
// Get environment
let env = setup();
// Increase test timeout
this.slow(env.slow);
this.timeout(env.timeout);
const productVariantId = env.PRODUCT_VARIANT_EQBISUMAS_10;
const couponCode = 'coupon10';
let cartId;
let cartEntryId;
/** Create cart and add coupon code to cart. */
beforeEach(function () {
return chai.request(env.openwhiskEndpoint)
.post(env.cartsPackage)
.send({
currency: 'USD',
quantity: 1,
productVariantId: productVariantId
})
.then(function (res) {
expect(res).to.be.json;
expect(res).to.have.status(HttpStatus.CREATED);
// Store cart id
cartId = res.body.id;
cartEntryId = res.body.entries[0].id;
return chai.request(env.openwhiskEndpoint)
.post(env.cartsPackage + `/${cartId}/coupons`)
.send({
code: couponCode
});
})
.then(function (res) {
expect(res).to.be.json;
expect(res).to.have.status(HttpStatus.OK);
expect(res.body).to.have.property('coupons');
expect(res.body.coupons).to.have.lengthOf(1);
let coupon = res.body.coupons[0];
expect(coupon).to.have.property('id');
expect(coupon).to.have.property('code');
expect(coupon.code).to.equal(couponCode);
});
});
/** Delete cart entry */
after(function () {
return chai.request(env.openwhiskEndpoint)
.delete(env.cartsPackage + `/${cartId}/entries/${cartEntryId}`)
.then(function (res) {
expect(res).to.be.json;
expect(res).to.have.status(HttpStatus.OK);
expect(res.body.entries).to.have.lengthOf(0);
});
});
it('deletes a coupon code from an existing cart', function () {
return chai.request(env.openwhiskEndpoint)
.delete(env.cartsPackage + `/${cartId}/coupons/${couponCode}`)
.then(function(res) {
expect(res).to.be.json;
expect(res).to.have.status(HttpStatus.OK);
requiredFields.verifyCart(res.body);
expect(res.body).to.not.have.property('coupons');
});
});
it('returns 404 for deleting a coupon code from a non existing cart', function () {
return chai.request(env.openwhiskEndpoint)
.delete(env.cartsPackage + `/does-not-exist/coupons/${couponCode}`)
.then(function(res) {
expect(res).to.have.status(HttpStatus.NOT_FOUND);
expect(res).to.be.json;
requiredFields.verifyErrorResponse(res.body);
});
});
it('returns 405 for a missing coupon code', function () {
return chai.request(env.openwhiskEndpoint)
.delete(env.cartsPackage + `/${cartId}/coupons/`)
.then(function(res) {
expect(res).to.have.status(HttpStatus.METHOD_NOT_ALLOWED);
});
});
});
});