-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathstart-campaigns-workflow-for-oidc-partner-test.js
186 lines (152 loc) · 6.47 KB
/
start-campaigns-workflow-for-oidc-partner-test.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* eslint ember/no-classic-classes: 0 */
import { visit } from '@1024pix/ember-testing-library';
import Service from '@ember/service';
import { click, currentURL, fillIn } from '@ember/test-helpers';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { t } from 'ember-intl/test-support';
import { setupApplicationTest } from 'ember-qunit';
import { currentSession } from 'ember-simple-auth/test-support';
import { module, test } from 'qunit';
import sinon from 'sinon';
import { authenticateByEmail } from '../../helpers/authentication';
import { clickByLabel } from '../../helpers/click-by-label';
import setupIntl from '../../helpers/setup-intl';
module('Acceptance | Campaigns | Start Campaigns workflow | OIDC', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIntl(hooks);
let campaign;
module('Start a campaign that belongs to an external provider', function () {
module('When user is not logged in', function (hooks) {
let replaceLocationStub;
hooks.beforeEach(function () {
replaceLocationStub = sinon.stub().resolves();
this.owner.register(
'service:location',
Service.extend({
replace: replaceLocationStub,
}),
);
campaign = server.create('campaign', { identityProvider: 'OIDC_PARTNER' });
});
test('should redirect to landing page', async function (assert) {
// given
const screen = await visit('/campagnes');
// when
await fillIn(
screen.getByRole('textbox', { name: `${t('pages.fill-in-campaign-code.label')} *` }),
campaign.code,
);
await clickByLabel(t('pages.fill-in-campaign-code.start'));
// then
assert.strictEqual(currentURL(), `/campagnes/${campaign.code}/presentation`);
});
test('should redirect to an oidc authentication form when landing page has been seen', async function (assert) {
// given
await visit(`/campagnes/${campaign.code}`);
// when
await clickByLabel('Je commence');
// then
assert.strictEqual(currentURL(), '/connexion/oidc-partner');
});
test('should redirect to login or register oidc page', async function (assert) {
// given
const state = 'state';
const session = currentSession();
session.set('data.state', state);
// when
const screen = await visit(`/connexion/oidc-partner?code=test&state=${state}`);
// then
assert.strictEqual(currentURL(), `/connexion/oidc?identityProviderSlug=oidc-partner`);
assert.ok(screen.getByRole('heading', { name: t('pages.login-or-register-oidc.title') }));
});
test('should begin campaign participation once user has accepted terms of service', async function (assert) {
// given
const state = 'state';
const session = currentSession();
session.set('data.state', state);
session.set('data.nextURL', `/campagnes/${campaign.code}/acces`);
const data = {};
data[campaign.code] = { landingPageShown: true };
sessionStorage.setItem('campaigns', JSON.stringify(data));
// when
const screen = await visit(`/connexion/oidc?identityProviderSlug=oidc-partner`);
await click(screen.getByRole('checkbox', { name: t('common.cgu.label') }));
await click(screen.getByRole('button', { name: 'Je crée mon compte' }));
// then
assert.strictEqual(currentURL(), `/campagnes/${campaign.code}/evaluation/didacticiel`);
});
});
module('When user is logged in', function (hooks) {
let replaceLocationStub;
hooks.beforeEach(async function () {
const prescritUser = server.create('user', 'withEmail', {
mustValidateTermsOfService: false,
lastTermsOfServiceValidatedAt: null,
});
await authenticateByEmail(prescritUser);
replaceLocationStub = sinon.stub().resolves();
this.owner.register(
'service:location',
Service.extend({
replace: replaceLocationStub,
}),
);
campaign = server.create('campaign', { identityProvider: 'OIDC_PARTNER' });
});
module('When user is logged in with an oidc organization', function (hooks) {
hooks.beforeEach(function () {
const session = currentSession();
session.set('data.authenticated.identityProviderCode', 'OIDC_PARTNER');
});
test('should redirect to landing page', async function (assert) {
// given
const screen = await visit('/campagnes');
// when
await fillIn(
screen.getByRole('textbox', { name: `${t('pages.fill-in-campaign-code.label')} *` }),
campaign.code,
);
await clickByLabel(t('pages.fill-in-campaign-code.start'));
// then
assert.strictEqual(currentURL(), `/campagnes/${campaign.code}/presentation`);
});
test('should begin campaign participation', async function (assert) {
// given
const screen = await visit('/campagnes');
await fillIn(
screen.getByRole('textbox', { name: `${t('pages.fill-in-campaign-code.label')} *` }),
campaign.code,
);
await clickByLabel(t('pages.fill-in-campaign-code.start'));
// when
await clickByLabel('Je commence');
// then
assert.strictEqual(currentURL(), `/campagnes/${campaign.code}/evaluation/didacticiel`);
});
});
module('When user is logged in with another authentication method', function () {
test('should redirect to landing page', async function (assert) {
// given
const screen = await visit('/campagnes');
// when
await fillIn(
screen.getByRole('textbox', { name: `${t('pages.fill-in-campaign-code.label')} *` }),
campaign.code,
);
await clickByLabel(t('pages.fill-in-campaign-code.start'));
// then
assert.strictEqual(currentURL(), `/campagnes/${campaign.code}/presentation`);
});
test('should redirect to oidc authentication form when landing page has been seen', async function (assert) {
// given
await visit(`/campagnes/${campaign.code}`);
// when
await clickByLabel('Je commence');
// then
assert.strictEqual(currentURL(), '/connexion/oidc-partner');
});
});
});
});
});