|
1 | | -import { moduleFor, test } from 'ember-qunit'; |
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupTest } from 'ember-qunit'; |
2 | 3 | import sinon from 'sinon'; |
3 | 4 | import StripeMock from 'ember-stripe-elements/utils/stripe-mock'; |
4 | 5 | import env from 'dummy/config/environment'; |
5 | 6 |
|
6 | | -moduleFor('service:stripev3', 'Unit | Service | stripev3', { |
7 | | - // Specify the other units that are required for this test. |
8 | | - needs: ['config:environment'], |
9 | | - beforeEach() { |
10 | | - window.Stripe = StripeMock; |
| 7 | +module('Unit | Service | stripev3', function(hooks) { |
| 8 | + setupTest(hooks); |
11 | 9 |
|
12 | | - this.stripe = this.subject({ |
| 10 | + hooks.beforeEach(function() { |
| 11 | + window.Stripe = StripeMock; |
| 12 | + this.subject = this.owner.factoryFor('service:stripev3').create({ |
13 | 13 | config: { |
14 | 14 | mock: true, |
15 | 15 | publishableKey: env.stripe.publishableKey |
16 | 16 | } |
17 | 17 | }); |
18 | | - } |
19 | | -}); |
| 18 | + }); |
20 | 19 |
|
21 | | -test('makes Stripe.elements available on the service', function(assert) { |
22 | | - assert.expect(1); |
| 20 | + test('makes Stripe.elements available on the service', function(assert) { |
| 21 | + assert.expect(1); |
23 | 22 |
|
24 | | - let service = this.subject(); |
25 | | - let mockOptions = { locale: 'en' }; |
| 23 | + let service = this.subject; |
| 24 | + let mockOptions = { locale: 'en' }; |
26 | 25 |
|
27 | | - let elements = sinon.stub(service, 'elements').callsFake(function(options) { |
28 | | - assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 26 | + let elements = sinon.stub(service, 'elements').callsFake(function(options) { |
| 27 | + assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 28 | + }); |
| 29 | + |
| 30 | + elements(mockOptions); |
| 31 | + elements.restore(); |
29 | 32 | }); |
30 | 33 |
|
31 | | - elements(mockOptions); |
32 | | - elements.restore(); |
33 | | -}); |
| 34 | + test('makes Stripe.createToken available on the service', function(assert) { |
| 35 | + assert.expect(1); |
34 | 36 |
|
35 | | -test('makes Stripe.createToken available on the service', function(assert) { |
36 | | - assert.expect(1); |
| 37 | + let service = this.subject; |
| 38 | + let mockOptions = { locale: 'en' }; |
37 | 39 |
|
38 | | - let service = this.subject(); |
39 | | - let mockOptions = { locale: 'en' }; |
| 40 | + let createToken = sinon.stub(service, 'createToken').callsFake(function(options) { |
| 41 | + assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 42 | + }); |
40 | 43 |
|
41 | | - let createToken = sinon.stub(service, 'createToken').callsFake(function(options) { |
42 | | - assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 44 | + createToken(mockOptions); |
| 45 | + createToken.restore(); |
43 | 46 | }); |
44 | 47 |
|
45 | | - createToken(mockOptions); |
46 | | - createToken.restore(); |
47 | | -}); |
| 48 | + test('makes Stripe.createSource available on the service', function(assert) { |
| 49 | + assert.expect(1); |
48 | 50 |
|
49 | | -test('makes Stripe.createSource available on the service', function(assert) { |
50 | | - assert.expect(1); |
| 51 | + let service = this.subject; |
| 52 | + let mockOptions = { locale: 'en' }; |
51 | 53 |
|
52 | | - let service = this.subject(); |
53 | | - let mockOptions = { locale: 'en' }; |
| 54 | + let createSource = sinon.stub(service, 'createSource').callsFake(function(options) { |
| 55 | + assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 56 | + }); |
54 | 57 |
|
55 | | - let createSource = sinon.stub(service, 'createSource').callsFake(function(options) { |
56 | | - assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 58 | + createSource(mockOptions); |
| 59 | + createSource.restore(); |
57 | 60 | }); |
58 | 61 |
|
59 | | - createSource(mockOptions); |
60 | | - createSource.restore(); |
61 | | -}); |
| 62 | + test('makes Stripe.retrieveSource available on the service', function(assert) { |
| 63 | + assert.expect(1); |
62 | 64 |
|
63 | | -test('makes Stripe.retrieveSource available on the service', function(assert) { |
64 | | - assert.expect(1); |
| 65 | + let service = this.subject; |
| 66 | + let mockOptions = { locale: 'en' }; |
65 | 67 |
|
66 | | - let service = this.subject(); |
67 | | - let mockOptions = { locale: 'en' }; |
| 68 | + let retrieveSource = sinon.stub(service, 'retrieveSource').callsFake(function(options) { |
| 69 | + assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 70 | + }); |
68 | 71 |
|
69 | | - let retrieveSource = sinon.stub(service, 'retrieveSource').callsFake(function(options) { |
70 | | - assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 72 | + retrieveSource(mockOptions); |
| 73 | + retrieveSource.restore(); |
71 | 74 | }); |
72 | 75 |
|
73 | | - retrieveSource(mockOptions); |
74 | | - retrieveSource.restore(); |
75 | | -}); |
| 76 | + test('makes Stripe.paymentRequest available on the service', function(assert) { |
| 77 | + assert.expect(1); |
76 | 78 |
|
77 | | -test('makes Stripe.paymentRequest available on the service', function(assert) { |
78 | | - assert.expect(1); |
| 79 | + let service = this.subject; |
| 80 | + let mockOptions = { locale: 'en' }; |
79 | 81 |
|
80 | | - let service = this.subject(); |
81 | | - let mockOptions = { locale: 'en' }; |
| 82 | + let paymentRequest = sinon.stub(service, 'paymentRequest').callsFake(function(options) { |
| 83 | + assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 84 | + }); |
82 | 85 |
|
83 | | - let paymentRequest = sinon.stub(service, 'paymentRequest').callsFake(function(options) { |
84 | | - assert.deepEqual(options, mockOptions, 'called with mock options'); |
| 86 | + paymentRequest(mockOptions); |
| 87 | + paymentRequest.restore(); |
85 | 88 | }); |
86 | | - |
87 | | - paymentRequest(mockOptions); |
88 | | - paymentRequest.restore(); |
89 | 89 | }); |
| 90 | + |
0 commit comments