Skip to content

Commit 9ff16c5

Browse files
committed
console: Fix flaky e2e test
1 parent 204ffe6 commit 9ff16c5

File tree

7 files changed

+58
-62
lines changed

7 files changed

+58
-62
lines changed

cypress/e2e/console/devices/device-on-othercluster.spec.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,13 @@ describe('End device on other cluster', () => {
2727
ids: { application_id: applicationId },
2828
}
2929

30-
const deviceId = 'device-all-components'
31-
3230
const ns = {
3331
end_device: {
3432
frequency_plan_id: 'EU_863_870_TTN',
3533
lorawan_phy_version: 'PHY_V1_0_2_REV_A',
3634
multicast: false,
3735
supports_join: true,
3836
lorawan_version: 'MAC_V1_0_2',
39-
ids: {
40-
device_id: deviceId,
41-
dev_eui: '70B3D57ED8000019',
42-
join_eui: '0000000000000000',
43-
},
4437
supports_class_c: false,
4538
supports_class_b: false,
4639
mac_settings: {
@@ -69,11 +62,6 @@ describe('End device on other cluster', () => {
6962

7063
const is = {
7164
end_device: {
72-
ids: {
73-
dev_eui: '9000BEEF9000BEEF',
74-
join_eui: '0000000000000000',
75-
device_id: 'device-all-components',
76-
},
7765
network_server_address: 'tti.staging1.cloud.thethings.industries',
7866
application_server_address: 'tti.staging1.cloud.thethings.industries',
7967
join_server_address: 'tti.staging1.cloud.thethings.industries',
@@ -83,11 +71,15 @@ describe('End device on other cluster', () => {
8371
},
8472
}
8573

74+
let deviceId
75+
8676
before(() => {
8777
cy.dropAndSeedDatabase()
8878
cy.createUser(user)
8979
cy.createApplication(application, user.ids.user_id)
90-
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is })
80+
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is }).then(body => {
81+
deviceId = body.end_device.ids.device_id
82+
})
9183
})
9284

9385
beforeEach(() => {

cypress/e2e/console/devices/device-overview.spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ describe('Device overview', () => {
2929
multicast: false,
3030
supports_join: false,
3131
lorawan_version: 'MAC_V1_0_2',
32-
ids: {
33-
device_id: 'device-all-components',
34-
dev_eui: '70B3D57ED8000019',
35-
},
3632
session: {
3733
keys: {
3834
f_nwk_s_int_key: {
@@ -52,13 +48,18 @@ describe('Device overview', () => {
5248
},
5349
},
5450
}
55-
const endDeviceId = ns.end_device.ids.device_id
51+
52+
let endDeviceId
53+
let endDeviceDevEui
5654

5755
before(() => {
5856
cy.dropAndSeedDatabase()
5957
cy.createUser(user)
6058
cy.createApplication(application, userId)
61-
cy.createMockDeviceAllComponents(appId, undefined, { ns })
59+
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
60+
endDeviceId = body.end_device.ids.device_id
61+
endDeviceDevEui = body.end_device.ids.dev_eui
62+
})
6263
})
6364

6465
beforeEach(() => {
@@ -86,7 +87,7 @@ describe('Device overview', () => {
8687
application_ids: {
8788
application_id: appId,
8889
},
89-
dev_eui: '70B3D57ED8000019',
90+
dev_eui: endDeviceDevEui,
9091
dev_addr: '270000FC',
9192
},
9293
created_at: '2021-07-06T21:32:48.499001538Z',

cypress/e2e/console/devices/edit.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ describe('Device general settings', () => {
3131
multicast: false,
3232
supports_join: false,
3333
lorawan_version: 'MAC_V1_0_2',
34-
ids: {
35-
device_id: 'device-all-components',
36-
dev_eui: '70B3D57ED8000019',
37-
},
3834
session: {
3935
keys: {
4036
f_nwk_s_int_key: {
@@ -54,13 +50,17 @@ describe('Device general settings', () => {
5450
},
5551
},
5652
}
57-
const endDeviceId = ns.end_device.ids.device_id
53+
let endDeviceId
54+
let endDeviceDevEui
5855

5956
before(() => {
6057
cy.dropAndSeedDatabase()
6158
cy.createUser(user)
6259
cy.createApplication(application, userId)
63-
cy.createMockDeviceAllComponents(appId, undefined, { ns })
60+
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
61+
endDeviceId = body.end_device.ids.device_id
62+
endDeviceDevEui = body.end_device.ids.dev_eui
63+
})
6464
})
6565

6666
beforeEach(() => {
@@ -82,7 +82,7 @@ describe('Device general settings', () => {
8282
cy.findByLabelText('DevEUI')
8383
.should('be.disabled')
8484
.and('have.attr', 'value')
85-
.and('eq', ns.end_device.ids.dev_eui)
85+
.and('eq', endDeviceDevEui)
8686

8787
cy.fixture('console/devices/device.is.json').then(endDevice => {
8888
cy.findByLabelText('End device name')

cypress/e2e/console/devices/unclaim.spec.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ describe('Device un-claiming', () => {
2929
multicast: false,
3030
supports_join: false,
3131
lorawan_version: 'MAC_V1_0_2',
32-
ids: {
33-
device_id: 'device-all-components',
34-
dev_eui: '70B3D57ED8000019',
35-
},
3632
session: {
3733
keys: {
3834
f_nwk_s_int_key: {
@@ -52,13 +48,19 @@ describe('Device un-claiming', () => {
5248
},
5349
},
5450
}
55-
const endDeviceId = ns.end_device.ids.device_id
51+
let endDeviceId
52+
let endDeviceDevEui
53+
let endDeviceJoinEui
5654

5755
before(() => {
5856
cy.dropAndSeedDatabase()
5957
cy.createUser(user)
6058
cy.createApplication(application, userId)
61-
cy.createMockDeviceAllComponents(appId, undefined, { ns })
59+
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
60+
endDeviceId = body.end_device.ids.device_id
61+
endDeviceDevEui = body.end_device.ids.dev_eui
62+
endDeviceJoinEui = body.end_device.ids.join_eui
63+
})
6264
})
6365

6466
beforeEach(() => {
@@ -92,9 +94,8 @@ describe('Device un-claiming', () => {
9294
const params = new URLSearchParams(new URL(url).search)
9395
const hexToBase64 = hex =>
9496
btoa(String.fromCharCode(...hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))))
95-
96-
expect(params.get('dev_eui')).to.equal(hexToBase64(ns.end_device.ids.dev_eui))
97-
expect(params.get('join_eui')).to.equal(hexToBase64('0000000000000000'))
97+
expect(params.get('dev_eui')).to.equal(hexToBase64(endDeviceDevEui))
98+
expect(params.get('join_eui')).to.equal(hexToBase64(endDeviceJoinEui))
9899
})
99100

100101
cy.findByTestId('error-notification').should('not.exist')

cypress/e2e/console/shared/payload-formatters/edit.spec.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ describe('Payload formatters', () => {
3737
fw_version: 'quickstart',
3838
band_id: 'EU_863_870',
3939
},
40-
ids: {
41-
device_id: 'device-all-components',
42-
dev_eui: '70B3D57ED8000013',
43-
join_eui: '0000000000000006',
44-
},
4540
supports_class_c: false,
4641
supports_class_b: false,
4742
mac_settings: {
@@ -75,11 +70,6 @@ describe('Payload formatters', () => {
7570

7671
const is = {
7772
end_device: {
78-
ids: {
79-
dev_eui: '70B3D57ED8000013',
80-
join_eui: '0000000000000006',
81-
device_id: 'device-all-components',
82-
},
8373
network_server_address: window.location.hostname,
8474
application_server_address: window.location.hostname,
8575
join_server_address: window.location.hostname,

cypress/e2e/smoke/devices/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
2828
const application = {
2929
ids: { application_id: applicationId },
3030
}
31-
const deviceId = 'device-all-components'
3231
const ns = {
3332
end_device: {
3433
frequency_plan_id: 'EU_863_870_TTN',
3534
lorawan_phy_version: 'PHY_V1_0_2_REV_B',
3635
multicast: false,
3736
supports_join: false,
3837
lorawan_version: 'MAC_V1_0_2',
39-
ids: {
40-
device_id: 'device-all-components',
41-
dev_eui: '70B3D57ED8000019',
42-
},
4338
session: {
4439
keys: {
4540
f_nwk_s_int_key: {
@@ -60,9 +55,13 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
6055
},
6156
}
6257

58+
let deviceId
59+
6360
cy.createUser(user)
6461
cy.createApplication(application, user.ids.user_id)
65-
cy.createMockDeviceAllComponents(applicationId, undefined, { ns })
62+
cy.createMockDeviceAllComponents(applicationId, undefined, { ns }).then(body => {
63+
deviceId = body.end_device.ids.device_id
64+
})
6665
cy.loginConsole({ user_id: user.ids.user_id, password: user.password })
6766
cy.visit(Cypress.config('consoleRootPath'))
6867

cypress/support/commands.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { noop, merge } from 'lodash'
1818

1919
import stringToHash from '../../pkg/webui/lib/string-to-hash'
2020

21+
import { generateHexValue } from './utils'
22+
2123
before(() => {
2224
cy.readFile('.env/admin_api_key.txt').then(adminKey => {
2325
Cypress.config('adminApiKey', adminKey)
@@ -319,16 +321,25 @@ Cypress.Commands.add(
319321
(
320322
applicationId,
321323
fixture = 'console/devices/device.*.json',
322-
overwrites = { ns: {}, as: {}, js: {}, is: {} },
324+
overwrites = {},
323325
injectHost = true,
324326
) => {
327+
const randomSuffix = Cypress._.random(0, 1e6)
328+
const deviceIds = {
329+
device_id: `device-${Date.now()}-${randomSuffix}`,
330+
dev_eui: generateHexValue(16).toUpperCase(),
331+
join_eui: generateHexValue(16).toUpperCase(),
332+
}
333+
const mergedOverwrites = Cypress._.merge({ ns: {}, as: {}, js: {}, is: {} }, overwrites)
334+
const { ns, as, js, is } = mergedOverwrites
325335
const baseUrl = Cypress.config('baseUrl')
326336
const adminApiKey = Cypress.config('adminApiKey')
327337
const interpolateFixture = (fixtureString, component) => fixtureString.replace('*', component)
328338
const headers = {
329339
Authorization: `Bearer ${adminApiKey}`,
330340
}
331341
cy.fixture(interpolateFixture(fixture, 'is')).then(body => {
342+
body.end_device.ids = deviceIds
332343
if (injectHost && body && 'end_device' in body) {
333344
if ('network_server_address' in body.end_device) {
334345
body.end_device.network_server_address = window.location.hostname
@@ -343,30 +354,30 @@ Cypress.Commands.add(
343354
cy.request({
344355
method: 'POST',
345356
url: `${baseUrl}/api/v3/applications/${applicationId}/devices`,
346-
body: { ...body, ...overwrites.is },
357+
body: Cypress._.merge({}, body, is),
347358
headers,
348-
failOnStatusCode: false,
349359
})
350360
})
351361
cy.fixture(interpolateFixture(fixture, 'ns')).then(body => {
362+
body.end_device.ids = deviceIds
352363
cy.request({
353364
method: 'PUT',
354365
url: `${baseUrl}/api/v3/ns/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
355-
body: { ...body, ...overwrites.ns },
366+
body: Cypress._.merge({}, body, ns),
356367
headers,
357-
failOnStatusCode: false,
358368
})
359369
})
360370
cy.fixture(interpolateFixture(fixture, 'as')).then(body => {
371+
body.end_device.ids = deviceIds
361372
cy.request({
362373
method: 'PUT',
363374
url: `${baseUrl}/api/v3/as/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
364-
body: { ...body, ...overwrites.as },
375+
body: Cypress._.merge({}, body, as),
365376
headers,
366-
failOnStatusCode: false,
367377
})
368378
})
369379
cy.fixture(interpolateFixture(fixture, 'js')).then(body => {
380+
body.end_device.ids = deviceIds
370381
if (injectHost && body && 'end_device' in body) {
371382
if ('network_server_address' in body.end_device) {
372383
body.end_device.network_server_address = window.location.hostname
@@ -378,12 +389,14 @@ Cypress.Commands.add(
378389
cy.request({
379390
method: 'PUT',
380391
url: `${baseUrl}/api/v3/js/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
381-
body: { ...body, ...overwrites.js },
392+
body: Cypress._.merge({}, body, js),
382393
headers,
383-
failOnStatusCode: false,
384394
})
385395
})
386-
return cy.fixture(interpolateFixture(fixture, 'is'))
396+
return cy.fixture(interpolateFixture(fixture, 'is')).then(body => {
397+
body.end_device.ids = deviceIds
398+
return body
399+
})
387400
},
388401
)
389402

0 commit comments

Comments
 (0)