Skip to content

Commit 998e005

Browse files
authored
feat: add overlay tests to create-org, rename test (#6403)
* add overlay tests to create-org, rename test * chore: add more specificity to cluster on org list page * chore: refactor to recycle test setup
1 parent e2a638f commit 998e005

File tree

2 files changed

+386
-133
lines changed

2 files changed

+386
-133
lines changed
Lines changed: 386 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,386 @@
1+
import {makeQuartzUseIDPEOrgID} from 'cypress/support/Utils'
2+
3+
const createOrgsFeatureFlags = {
4+
createDeleteOrgs: true,
5+
}
6+
7+
const newOrgName = 'A New Org'
8+
9+
// This variable stores the current IDPE orgid and syncs it with the quartz-mock orgid.
10+
let idpeOrgID: string
11+
12+
const getOrgCreationAllowance = (allowanceFixture: string) => {
13+
cy.intercept('GET', 'api/v2/quartz/allowances/orgs/create', {
14+
fixture: allowanceFixture,
15+
}).as('getAllowancesOrgsCreate')
16+
}
17+
18+
const clickCreateOrgButton = () => {
19+
cy.getByTestID('globalheader--org-dropdown').should('exist').click()
20+
21+
cy.getByTestID('globalheader--org-dropdown-main').should('be.visible')
22+
cy.getByTestID('global-header--main-dropdown-item-Create Organization')
23+
.should('be.visible')
24+
.click()
25+
cy.getByTestID('create-org-overlay--header').contains(
26+
'Create an Organization'
27+
)
28+
}
29+
30+
const clickUpgradeButton = () => {
31+
cy.getByTestID('globalheader--org-dropdown').should('exist').click()
32+
cy.getByTestID('globalheader--org-dropdown-main').should('be.visible')
33+
cy.getByTestID('globalheader--org-dropdown-main-Add More Organizations')
34+
.should('be.visible')
35+
.click()
36+
}
37+
38+
const tryCreatingDuplicateOrg = () => {
39+
cy.getByTestID('create-org-overlay--createorg-input')
40+
.should('be.visible')
41+
.click()
42+
.type('E2E Test Organization')
43+
44+
cy.getByTestID('form--element-error')
45+
.should('be.visible')
46+
.contains(
47+
'This organization name already exists. Please choose a different name'
48+
)
49+
50+
cy.getByTestID('create-org-form--submit').should(
51+
'have.class',
52+
'cf-button--disabled'
53+
)
54+
}
55+
56+
const testMarketoForm = () => {
57+
// This intercept is important to ensure we don't actually POST the form contents.
58+
cy.intercept('POST', `https://get.influxdata.com/**`, {
59+
formID: '2826',
60+
followUpUrl: null,
61+
aliId: 'Fake ID',
62+
}).as('marketoResponse')
63+
64+
cy.wait(2000)
65+
66+
cy.getByTestID('marketo-account-upgrade-form--userinput')
67+
.should('be.visible')
68+
.type('Internal InfluxData End to End Test.')
69+
70+
cy.getByTestID('create-org-form-submit').should('be.visible').click()
71+
72+
cy.wait('@marketoResponse').then(res => {
73+
expect(res?.response?.body.formID).to.equal('2826')
74+
})
75+
76+
cy.getByTestID('notification-success')
77+
.should('be.visible')
78+
.contains('Your account upgrade inquiry has been submitted.')
79+
}
80+
81+
const testProviderCards = () => {
82+
cy.getByTestID('create-org-overlay--select-Azure-card')
83+
.should('be.visible')
84+
.click()
85+
cy.getByTestID('create-org-overlay--select-Azure-card').should(
86+
'have.class',
87+
'selected'
88+
)
89+
90+
cy.getByTestID('create-org-overlay--select-AWS-card')
91+
.should('be.visible')
92+
.click()
93+
cy.getByTestID('create-org-overlay--select-AWS-card').should(
94+
'have.class',
95+
'selected'
96+
)
97+
98+
cy.getByTestID('create-org-overlay--select-GCP-card')
99+
.should('be.visible')
100+
.click()
101+
cy.getByTestID('create-org-overlay--select-GCP-card').should(
102+
'have.class',
103+
'selected'
104+
)
105+
}
106+
107+
interface SetupParams {
108+
accountType: string
109+
canCreateOrgs: boolean
110+
urlToVisit?: string
111+
}
112+
113+
const setupTest = (setupParams: SetupParams) => {
114+
cy.flush().then(() =>
115+
cy.signin().then(() => {
116+
cy.setFeatureFlags(createOrgsFeatureFlags)
117+
cy.request({
118+
method: 'GET',
119+
url: 'api/v2/orgs',
120+
}).then(res => {
121+
// Store the IDPE org ID so that it can be cloned when intercepting quartz.
122+
if (res.body.orgs) {
123+
idpeOrgID = res.body.orgs[0].id
124+
}
125+
const {accountType, canCreateOrgs, urlToVisit} = setupParams
126+
127+
makeQuartzUseIDPEOrgID(idpeOrgID, accountType)
128+
129+
// Intercept requests to /clusters and /accounts/:accountId/orgs and replace with a fixture.
130+
cy.intercept('GET', 'api/v2/quartz/clusters', {
131+
fixture: 'createOrg/clusters',
132+
}).as('getClusters')
133+
134+
cy.intercept('GET', 'api/v2/quartz/accounts/416/orgs', {
135+
fixture: 'createOrg/orgsBaseState',
136+
}).as('getOrgs')
137+
138+
let fixtureName: string
139+
if (accountType === 'free') {
140+
fixtureName = canCreateOrgs
141+
? 'createOrg/allowanceFreeTrue'
142+
: 'createOrg/allowanceFreeFalse'
143+
} else if (accountType === 'pay_as_you_go') {
144+
fixtureName = canCreateOrgs
145+
? 'createOrg/allowancePAYGTrue'
146+
: 'createOrg/allowancePAYGFalse'
147+
} else {
148+
fixtureName = canCreateOrgs
149+
? 'createOrg/allowanceContractTrue'
150+
: 'createOrg/allowanceContractFalse'
151+
}
152+
153+
// Replace the current org creation allowance with a fixture.
154+
getOrgCreationAllowance(fixtureName)
155+
156+
// If a url is specified, start the test at that url.
157+
if (urlToVisit) {
158+
cy.visit(`orgs/${idpeOrgID}/` + urlToVisit)
159+
} else {
160+
cy.visit('/')
161+
}
162+
})
163+
})
164+
)
165+
}
166+
167+
describe('Free account', () => {
168+
it('by default, cant create orgs: displays the `add more organizations` upgrade button, which takes user to checkout', () => {
169+
setupTest({accountType: 'free', canCreateOrgs: false})
170+
171+
clickUpgradeButton()
172+
173+
cy.url().should('include', '/checkout')
174+
})
175+
176+
it('can create new orgs, if the free account allowance is increased', () => {
177+
setupTest({accountType: 'free', canCreateOrgs: true})
178+
179+
clickCreateOrgButton()
180+
181+
cy.getByTestID('create-org-overlay--createorg-input')
182+
.should('be.visible')
183+
.click()
184+
.type(newOrgName)
185+
186+
testProviderCards()
187+
188+
cy.getByTestID('create-org-overlay--select-GCP-card')
189+
.should('be.visible')
190+
.click()
191+
cy.getByTestID('create-org-overlay--select-GCP-card').should(
192+
'have.class',
193+
'selected'
194+
)
195+
cy.getByTestID('region-list-dropdown--button').should('be.visible').click()
196+
197+
cy.getByTestID('region-list-dropdown')
198+
.should('be.visible')
199+
.contains('Iowa')
200+
.click()
201+
202+
cy.intercept('GET', 'api/v2/quartz/accounts/416/orgs', {
203+
fixture: 'createOrg/orgsUpdatedStateFree',
204+
}).as('getOrgs')
205+
206+
cy.intercept('POST', 'api/v2/quartz/orgs', {
207+
fixture: 'createOrg/orgFree',
208+
}).as('postOrg')
209+
210+
cy.getByTestID('create-org-form--submit').should('be.visible').click()
211+
212+
cy.wait('@getOrgs').then(() => {
213+
cy.getByTestID('notification-success')
214+
.should('be.visible')
215+
.contains('created')
216+
cy.url().should('contain', 'orglist')
217+
cy.getByTestID('account--organizations-tab-orgs-card')
218+
.contains(newOrgName)
219+
.parents('[data-testid=account--organizations-tab-orgs-card]')
220+
.within(() => {
221+
cy.contains('GCP')
222+
cy.contains('iowa-local')
223+
cy.contains('Iowa')
224+
})
225+
})
226+
})
227+
})
228+
229+
describe('PAYG account', () => {
230+
it('can create new orgs, if there are orgs left in the quota', () => {
231+
setupTest({accountType: 'pay_as_you_go', canCreateOrgs: true})
232+
233+
clickCreateOrgButton()
234+
235+
cy.getByTestID('create-org-overlay--createorg-input')
236+
.should('be.visible')
237+
.click()
238+
.type(newOrgName)
239+
240+
testProviderCards()
241+
242+
cy.getByTestID('create-org-overlay--select-Azure-card')
243+
.should('be.visible')
244+
.click()
245+
cy.getByTestID('create-org-overlay--select-Azure-card').should(
246+
'have.class',
247+
'selected'
248+
)
249+
cy.getByTestID('region-list-dropdown--button').should('be.visible').click()
250+
251+
cy.getByTestID('region-list-dropdown')
252+
.should('be.visible')
253+
.contains('Amsterdam')
254+
.click()
255+
256+
cy.intercept('GET', 'api/v2/quartz/accounts/416/orgs', {
257+
fixture: 'createOrg/orgsUpdatedStatePAYG',
258+
}).as('getOrgs')
259+
260+
cy.intercept('POST', 'api/v2/quartz/orgs', {
261+
fixture: 'createOrg/orgPAYG',
262+
}).as('postOrg')
263+
264+
cy.getByTestID('create-org-form--submit').should('be.visible').click()
265+
266+
cy.wait('@getOrgs').then(() => {
267+
cy.getByTestID('notification-success')
268+
.should('be.visible')
269+
.contains('created')
270+
cy.url().should('contain', 'orglist')
271+
cy.getByTestID('account--organizations-tab-orgs-card')
272+
.contains(newOrgName)
273+
.parents('[data-testid=account--organizations-tab-orgs-card]')
274+
.within(() => {
275+
cy.contains('Azure')
276+
cy.contains('azure-local')
277+
cy.contains('azure-local region')
278+
})
279+
})
280+
})
281+
282+
it('cant create an org with the same name as another org in the account', () => {
283+
setupTest({accountType: 'pay_as_you_go', canCreateOrgs: true})
284+
285+
clickCreateOrgButton()
286+
287+
tryCreatingDuplicateOrg()
288+
})
289+
290+
it('must upgrade the account using the marketo form, if there are no orgs left in the quota', () => {
291+
setupTest({accountType: 'pay_as_you_go', canCreateOrgs: false})
292+
293+
clickUpgradeButton()
294+
295+
testMarketoForm()
296+
})
297+
})
298+
299+
describe('CONTRACT account: org creation', () => {
300+
it('can create new orgs, if orgs in quota', () => {
301+
setupTest({accountType: 'contract', canCreateOrgs: true})
302+
clickCreateOrgButton()
303+
304+
cy.getByTestID('create-org-overlay--createorg-input')
305+
.should('be.visible')
306+
.click()
307+
.type(newOrgName)
308+
309+
testProviderCards()
310+
311+
cy.getByTestID('create-org-overlay--select-AWS-card')
312+
.should('be.visible')
313+
.click()
314+
315+
cy.getByTestID('create-org-overlay--select-AWS-card').should(
316+
'have.class',
317+
'selected'
318+
)
319+
320+
cy.getByTestID('region-list-dropdown--button').should('be.visible').click()
321+
cy.getByTestID('region-list-dropdown').contains('US West (Oregon)').click()
322+
323+
cy.intercept('POST', 'api/v2/quartz/orgs', {
324+
fixture: 'createOrg/orgContract',
325+
}).as('orgContract')
326+
327+
cy.intercept('GET', 'api/v2/quartz/accounts/416/orgs', {
328+
fixture: 'createOrg/orgsUpdatedStateContract',
329+
}).as('getOrgs')
330+
331+
cy.getByTestID('create-org-form--submit').should('be.visible').click()
332+
333+
cy.wait('@orgContract').then(() => {
334+
cy.getByTestID('notification-success')
335+
.should('be.visible')
336+
.contains('created')
337+
cy.url().should('contain', 'orglist')
338+
cy.getByTestID('account--organizations-tab-orgs-card')
339+
.contains(newOrgName)
340+
.parents('[data-testid=account--organizations-tab-orgs-card]')
341+
.within(() => {
342+
cy.contains('AWS')
343+
cy.contains('aws-local')
344+
cy.contains('aws-local region')
345+
})
346+
})
347+
})
348+
349+
it('cant create an org with the same name as another org in the account', () => {
350+
setupTest({accountType: 'contract', canCreateOrgs: true})
351+
clickCreateOrgButton()
352+
353+
tryCreatingDuplicateOrg()
354+
})
355+
356+
it('must upgrade using marketo form, if no more orgs in quota, which is accessible only from the organization list page in contract accounts', () => {
357+
setupTest({
358+
accountType: 'contract',
359+
canCreateOrgs: false,
360+
urlToVisit: 'accounts/orglist',
361+
})
362+
363+
cy.getByTestID('globalheader--org-dropdown').should('exist').click()
364+
cy.getByTestID('globalheader--org-dropdown-main').should('be.visible')
365+
/* 'Upgrade' button in the dropdown doesn't show in contract accounts
366+
at their org limit, to avoid annoying a customer that has already upgraded.
367+
In contract orgs, the upgrade link appears only on the organization list page. */
368+
369+
cy.getByTestID(
370+
'globalheader--org-dropdown-main-Add More Organizations'
371+
).should('not.exist')
372+
373+
cy.getByTestID('globalheader--org-dropdown').should('be.visible').click()
374+
375+
cy.getByTestID('account-settings-page-org-tab--upgrade-banner-text')
376+
.should('be.visible')
377+
.click()
378+
379+
// Not targeting by testID because standard anchor tags don't have that property.
380+
cy.get('.account-settings-page-org-tab--quota-limit-link')
381+
.should('be.visible')
382+
.click()
383+
384+
testMarketoForm()
385+
})
386+
})

0 commit comments

Comments
 (0)