Skip to content

Commit 204ffe6

Browse files
committed
Revert "console: Fix flaky e2e test"
This reverts commit a13ee8f.
1 parent a13ee8f commit 204ffe6

File tree

7 files changed

+71
-101
lines changed

7 files changed

+71
-101
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { generateHexValue } from '../../../support/utils'
16-
1715
describe('End device on other cluster', () => {
1816
const userId = 'cluster-test-user'
1917
const user = {
@@ -29,9 +27,7 @@ describe('End device on other cluster', () => {
2927
ids: { application_id: applicationId },
3028
}
3129

32-
const deviceId = `device-${Date.now()}`
33-
const uniqueDevEui = generateHexValue(16)
34-
const uniqueJoinEui = generateHexValue(16)
30+
const deviceId = 'device-all-components'
3531

3632
const ns = {
3733
end_device: {
@@ -42,8 +38,8 @@ describe('End device on other cluster', () => {
4238
lorawan_version: 'MAC_V1_0_2',
4339
ids: {
4440
device_id: deviceId,
45-
dev_eui: uniqueDevEui,
46-
join_eui: uniqueJoinEui,
41+
dev_eui: '70B3D57ED8000019',
42+
join_eui: '0000000000000000',
4743
},
4844
supports_class_c: false,
4945
supports_class_b: false,
@@ -74,9 +70,9 @@ describe('End device on other cluster', () => {
7470
const is = {
7571
end_device: {
7672
ids: {
77-
dev_eui: uniqueDevEui,
78-
join_eui: uniqueJoinEui,
79-
device_id: deviceId,
73+
dev_eui: '9000BEEF9000BEEF',
74+
join_eui: '0000000000000000',
75+
device_id: 'device-all-components',
8076
},
8177
network_server_address: 'tti.staging1.cloud.thethings.industries',
8278
application_server_address: 'tti.staging1.cloud.thethings.industries',

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { generateHexValue } from '../../../support/utils'
16-
1715
describe('Device overview', () => {
1816
const appId = 'end-device-mac-data-test-application'
1917
const application = { ids: { application_id: appId } }
@@ -24,9 +22,6 @@ describe('Device overview', () => {
2422
password: 'ABCDefg123!',
2523
password_confirm: 'ABCDefg123!',
2624
}
27-
28-
const endDeviceId = `device-${Date.now()}`
29-
3025
const ns = {
3126
end_device: {
3227
frequency_plan_id: 'EU_863_870_TTN',
@@ -35,8 +30,8 @@ describe('Device overview', () => {
3530
supports_join: false,
3631
lorawan_version: 'MAC_V1_0_2',
3732
ids: {
38-
device_id: endDeviceId,
39-
dev_eui: generateHexValue(16),
33+
device_id: 'device-all-components',
34+
dev_eui: '70B3D57ED8000019',
4035
},
4136
session: {
4237
keys: {
@@ -57,6 +52,7 @@ describe('Device overview', () => {
5752
},
5853
},
5954
}
55+
const endDeviceId = ns.end_device.ids.device_id
6056

6157
before(() => {
6258
cy.dropAndSeedDatabase()

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ describe('Device general settings', () => {
2424
password: 'ABCDefg123!',
2525
password_confirm: 'ABCDefg123!',
2626
}
27-
const endDeviceId = `device-${Date.now()}`
28-
const endDeviceDevEui = generateHexValue(16)
2927
const ns = {
3028
end_device: {
3129
frequency_plan_id: 'EU_863_870_TTN',
@@ -34,8 +32,8 @@ describe('Device general settings', () => {
3432
supports_join: false,
3533
lorawan_version: 'MAC_V1_0_2',
3634
ids: {
37-
device_id: endDeviceId,
38-
dev_eui: endDeviceDevEui,
35+
device_id: 'device-all-components',
36+
dev_eui: '70B3D57ED8000019',
3937
},
4038
session: {
4139
keys: {
@@ -56,6 +54,7 @@ describe('Device general settings', () => {
5654
},
5755
},
5856
}
57+
const endDeviceId = ns.end_device.ids.device_id
5958

6059
before(() => {
6160
cy.dropAndSeedDatabase()
@@ -83,7 +82,7 @@ describe('Device general settings', () => {
8382
cy.findByLabelText('DevEUI')
8483
.should('be.disabled')
8584
.and('have.attr', 'value')
86-
.and('eq', endDeviceDevEui)
85+
.and('eq', ns.end_device.ids.dev_eui)
8786

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

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { generateHexValue } from '../../../support/utils'
16-
1715
describe('Device un-claiming', () => {
1816
const appId = 'end-device-edit-test-application'
1917
const application = { ids: { application_id: appId } }
@@ -24,7 +22,6 @@ describe('Device un-claiming', () => {
2422
password: 'ABCDefg123!',
2523
password_confirm: 'ABCDefg123!',
2624
}
27-
2825
const ns = {
2926
end_device: {
3027
frequency_plan_id: 'EU_863_870_TTN',
@@ -33,8 +30,8 @@ describe('Device un-claiming', () => {
3330
supports_join: false,
3431
lorawan_version: 'MAC_V1_0_2',
3532
ids: {
36-
device_id: `device-${Date.now()}`,
37-
dev_eui: generateHexValue(16),
33+
device_id: 'device-all-components',
34+
dev_eui: '70B3D57ED8000019',
3835
},
3936
session: {
4037
keys: {
@@ -56,15 +53,12 @@ describe('Device un-claiming', () => {
5653
},
5754
}
5855
const endDeviceId = ns.end_device.ids.device_id
59-
let devEui
6056

6157
before(() => {
6258
cy.dropAndSeedDatabase()
6359
cy.createUser(user)
6460
cy.createApplication(application, userId)
65-
cy.createMockDeviceAllComponents(appId, undefined, { ns }).then(body => {
66-
devEui = body.end_device.ids.dev_eui
67-
})
61+
cy.createMockDeviceAllComponents(appId, undefined, { ns })
6862
})
6963

7064
beforeEach(() => {
@@ -99,7 +93,7 @@ describe('Device un-claiming', () => {
9993
const hexToBase64 = hex =>
10094
btoa(String.fromCharCode(...hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))))
10195

102-
expect(params.get('dev_eui')).to.equal(hexToBase64(devEui))
96+
expect(params.get('dev_eui')).to.equal(hexToBase64(ns.end_device.ids.dev_eui))
10397
expect(params.get('join_eui')).to.equal(hexToBase64('0000000000000000'))
10498
})
10599

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { generateHexValue } from '../../../../support/utils'
16-
1715
describe('Payload formatters', () => {
1816
const applicationId = 'test-application-payload-formatters'
1917
const application = { ids: { application_id: applicationId } }
@@ -25,10 +23,6 @@ describe('Payload formatters', () => {
2523
password_confirm: 'ABCDefg123!',
2624
}
2725

28-
const endDeviceId = `device-${Date.now()}`
29-
const devEui = generateHexValue(16)
30-
const joinEui = generateHexValue(16)
31-
3226
const ns = {
3327
end_device: {
3428
frequency_plan_id: 'EU_863_870_TTN',
@@ -44,9 +38,9 @@ describe('Payload formatters', () => {
4438
band_id: 'EU_863_870',
4539
},
4640
ids: {
47-
device_id: endDeviceId,
48-
dev_eui: devEui,
49-
join_eui: joinEui,
41+
device_id: 'device-all-components',
42+
dev_eui: '70B3D57ED8000013',
43+
join_eui: '0000000000000006',
5044
},
5145
supports_class_c: false,
5246
supports_class_b: false,
@@ -81,17 +75,10 @@ describe('Payload formatters', () => {
8175

8276
const is = {
8377
end_device: {
84-
version_ids: {
85-
brand_id: 'the-things-products',
86-
model_id: 'the-things-uno',
87-
hw_version: '1.0',
88-
fw_version: 'quickstart',
89-
band_id: 'EU_863_870',
90-
},
9178
ids: {
92-
dev_eui: devEui,
93-
join_eui: joinEui,
94-
device_id: endDeviceId,
79+
dev_eui: '70B3D57ED8000013',
80+
join_eui: '0000000000000006',
81+
device_id: 'device-all-components',
9582
},
9683
network_server_address: window.location.hostname,
9784
application_server_address: window.location.hostname,
@@ -102,12 +89,15 @@ describe('Payload formatters', () => {
10289
},
10390
}
10491

92+
let endDeviceId
10593
before(() => {
10694
cy.dropAndSeedDatabase()
10795
cy.createUser(user)
10896
cy.createApplication(application, userId)
10997
cy.setApplicationPayloadFormatter(applicationId)
110-
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is })
98+
cy.createMockDeviceAllComponents(applicationId, undefined, { ns, is }).then(body => {
99+
endDeviceId = body.end_device.ids.device_id
100+
})
111101
})
112102

113103
describe('Application', () => {
@@ -476,7 +466,11 @@ describe('Payload formatters', () => {
476466
const repositoryFormatter = {
477467
formatter_parameter: 'Test formatter parameter',
478468
}
479-
cy.intercept('GET', `/api/v3/dr/applications/${applicationId}/**`, repositoryFormatter)
469+
cy.intercept(
470+
'GET',
471+
`/api/v3/dr/applications/test-application-payload-formatters/**`,
472+
repositoryFormatter,
473+
)
480474

481475
cy.visit(
482476
`${Cypress.config(

cypress/e2e/smoke/devices/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
import { defineSmokeTest } from '../utils'
16-
import { generateHexValue } from '../../../support/utils'
1716

1817
const checkCollapsingFields = defineSmokeTest('check all end device sub pages', () => {
1918
const userId = 'device-subpage-test-user'
@@ -29,8 +28,7 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
2928
const application = {
3029
ids: { application_id: applicationId },
3130
}
32-
const deviceId = `device-${Date.now()}`
33-
31+
const deviceId = 'device-all-components'
3432
const ns = {
3533
end_device: {
3634
frequency_plan_id: 'EU_863_870_TTN',
@@ -39,8 +37,8 @@ const checkCollapsingFields = defineSmokeTest('check all end device sub pages',
3937
supports_join: false,
4038
lorawan_version: 'MAC_V1_0_2',
4139
ids: {
42-
device_id: deviceId,
43-
dev_eui: generateHexValue(16),
40+
device_id: 'device-all-components',
41+
dev_eui: '70B3D57ED8000019',
4442
},
4543
session: {
4644
keys: {

cypress/support/commands.js

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -324,73 +324,66 @@ Cypress.Commands.add(
324324
) => {
325325
const baseUrl = Cypress.config('baseUrl')
326326
const adminApiKey = Cypress.config('adminApiKey')
327-
const headers = { Authorization: `Bearer ${adminApiKey}` }
328-
329-
const deviceId = `device-${Date.now()}`
330-
331-
const prepareBody = body => {
332-
const clone = Cypress._.cloneDeep(body)
333-
if (clone?.end_device?.ids) {
334-
clone.end_device.ids.device_id =
335-
overwrites.is?.end_device?.ids?.device_id ||
336-
overwrites.ns?.end_device?.ids?.device_id ||
337-
overwrites.as?.end_device?.ids?.device_id ||
338-
overwrites.js?.end_device?.ids?.device_id ||
339-
deviceId
340-
}
341-
return clone
327+
const interpolateFixture = (fixtureString, component) => fixtureString.replace('*', component)
328+
const headers = {
329+
Authorization: `Bearer ${adminApiKey}`,
342330
}
343-
344-
const load = part => cy.fixture(fixture.replace('*', part)).then(prepareBody)
345-
346-
load('is').then(body => {
347-
if (injectHost && body?.end_device) {
348-
const host = window.location.hostname
349-
body.end_device.network_server_address = host
350-
body.end_device.join_server_address = host
351-
body.end_device.application_server_address = host
331+
cy.fixture(interpolateFixture(fixture, 'is')).then(body => {
332+
if (injectHost && body && 'end_device' in body) {
333+
if ('network_server_address' in body.end_device) {
334+
body.end_device.network_server_address = window.location.hostname
335+
}
336+
if ('join_server_address' in body.end_device) {
337+
body.end_device.join_server_address = window.location.hostname
338+
}
339+
if ('application_server_address' in body.end_device) {
340+
body.end_device.application_server_address = window.location.hostname
341+
}
352342
}
353343
cy.request({
354344
method: 'POST',
355345
url: `${baseUrl}/api/v3/applications/${applicationId}/devices`,
356346
body: { ...body, ...overwrites.is },
357347
headers,
348+
failOnStatusCode: false,
358349
})
359350
})
360-
361-
load('ns').then(body =>
351+
cy.fixture(interpolateFixture(fixture, 'ns')).then(body => {
362352
cy.request({
363353
method: 'PUT',
364-
url: `${baseUrl}/api/v3/ns/applications/${applicationId}/devices/${deviceId}`,
354+
url: `${baseUrl}/api/v3/ns/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
365355
body: { ...body, ...overwrites.ns },
366356
headers,
367-
}),
368-
)
369-
370-
load('as').then(body =>
357+
failOnStatusCode: false,
358+
})
359+
})
360+
cy.fixture(interpolateFixture(fixture, 'as')).then(body => {
371361
cy.request({
372362
method: 'PUT',
373-
url: `${baseUrl}/api/v3/as/applications/${applicationId}/devices/${deviceId}`,
363+
url: `${baseUrl}/api/v3/as/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
374364
body: { ...body, ...overwrites.as },
375365
headers,
376-
}),
377-
)
378-
379-
load('js').then(body => {
380-
if (injectHost && body?.end_device) {
381-
const host = window.location.hostname
382-
body.end_device.network_server_address = host
383-
body.end_device.application_server_address = host
366+
failOnStatusCode: false,
367+
})
368+
})
369+
cy.fixture(interpolateFixture(fixture, 'js')).then(body => {
370+
if (injectHost && body && 'end_device' in body) {
371+
if ('network_server_address' in body.end_device) {
372+
body.end_device.network_server_address = window.location.hostname
373+
}
374+
if ('application_server_address' in body.end_device) {
375+
body.end_device.application_server_address = window.location.hostname
376+
}
384377
}
385378
cy.request({
386379
method: 'PUT',
387-
url: `${baseUrl}/api/v3/js/applications/${applicationId}/devices/${deviceId}`,
380+
url: `${baseUrl}/api/v3/js/applications/${applicationId}/devices/${body.end_device.ids.device_id}`,
388381
body: { ...body, ...overwrites.js },
389382
headers,
383+
failOnStatusCode: false,
390384
})
391385
})
392-
393-
return cy.fixture(fixture.replace('*', 'is')).then(prepareBody)
386+
return cy.fixture(interpolateFixture(fixture, 'is'))
394387
},
395388
)
396389

0 commit comments

Comments
 (0)