Skip to content

Commit 5ea2169

Browse files
committed
test(e2e): remove need to fetch deviceIdentity
deviceId and model will be provided in a link
1 parent 8ebf039 commit 5ea2169

File tree

3 files changed

+17
-115
lines changed

3 files changed

+17
-115
lines changed

feature-runner/run-features.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import path from 'node:path'
66
import type { StackOutputs as BackendStackOutputs } from '../cdk/stacks/BackendStack.js'
77
import { STACK_NAME } from '../cdk/stacks/stackConfig.js'
88
import { steps as storageSteps } from '@hello.nrfcloud.com/bdd-markdown-steps/storage'
9-
import { steps as randomSteps } from '@hello.nrfcloud.com/bdd-markdown-steps/random'
9+
import {
10+
steps as randomSteps,
11+
email,
12+
IMEI,
13+
} from '@hello.nrfcloud.com/bdd-markdown-steps/random'
1014
import { steps as deviceSteps } from './steps/device.js'
1115
import { steps as RESTSteps } from '@hello.nrfcloud.com/bdd-markdown-steps/REST'
1216
import { IoTDataPlaneClient } from '@aws-sdk/client-iot-data-plane'
13-
import { fromEnv } from '@nordicsemiconductor/from-env'
14-
import { mock as httpApiMock } from '@bifravst/http-api-mock/mock'
15-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
1617
import { slashless } from '@hello.nrfcloud.com/nrfcloud-api-helpers/api'
1718

1819
/**
@@ -23,18 +24,11 @@ import { slashless } from '@hello.nrfcloud.com/nrfcloud-api-helpers/api'
2324
*/
2425

2526
const iotData = new IoTDataPlaneClient({})
26-
const db = new DynamoDBClient({})
2727

2828
const backendConfig = await stackOutput(
2929
new CloudFormationClient({}),
3030
)<BackendStackOutputs>(STACK_NAME)
3131

32-
const { mockApiEndpoint, responsesTableName } = fromEnv({
33-
mockApiEndpoint: 'HTTP_API_MOCK_API_URL',
34-
responsesTableName: 'HTTP_API_MOCK_RESPONSES_TABLE_NAME',
35-
requestsTableName: 'HTTP_API_MOCK_REQUESTS_TABLE_NAME',
36-
})(process.env)
37-
3832
const print = (arg: unknown) =>
3933
typeof arg === 'object' ? JSON.stringify(arg) : arg
4034
const start = Date.now()
@@ -80,27 +74,23 @@ const runner = await runFolder({
8074

8175
const cleaners: (() => Promise<void>)[] = []
8276

83-
const describeOOBDeviceAPIBasePath = 'hello.nrfcloud.com/api/device'
8477
runner
8578
.addStepRunners(...storageSteps)
86-
.addStepRunners(...randomSteps())
79+
.addStepRunners(
80+
...randomSteps({
81+
email,
82+
'device ID': () => `oob-${IMEI()}`,
83+
}),
84+
)
8785
.addStepRunners(...RESTSteps)
8886
.addStepRunners(
8987
...deviceSteps({
9088
iotData,
91-
httpApiMock: httpApiMock({
92-
db,
93-
responsesTable: responsesTableName,
94-
}),
95-
describeOOBDeviceAPIBasePath,
9689
}),
9790
)
9891

9992
const res = await runner.run({
10093
API: slashless(new URL(backendConfig.APIURL)),
101-
describeOOBDeviceAPI: new URL(
102-
`${mockApiEndpoint}${describeOOBDeviceAPIBasePath}`,
103-
),
10494
})
10595

10696
await Promise.all(cleaners.map(async (fn) => fn()))

feature-runner/steps/device.ts

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,6 @@ import {
99
type StepRunner,
1010
} from '@nordicsemiconductor/bdd-markdown'
1111
import { Type } from '@sinclair/typebox'
12-
import { fingerprintGenerator } from '@hello.nrfcloud.com/proto/fingerprint'
13-
import { IMEI } from '@hello.nrfcloud.com/bdd-markdown-steps/random'
14-
import type { HttpAPIMock } from '@bifravst/http-api-mock/mock'
15-
16-
const getCurrentWeekNumber = (): number => {
17-
const now = new Date()
18-
const firstOfJanuary = new Date(now.getFullYear(), 0, 1)
19-
return Math.ceil(
20-
((now.getTime() - firstOfJanuary.getTime()) / 86400000 +
21-
firstOfJanuary.getDay() +
22-
1) /
23-
7,
24-
)
25-
}
26-
27-
const oobDeviceWithFingerprint = (
28-
httpApiMock: HttpAPIMock,
29-
describeOOBDeviceAPIBasePath: string,
30-
) =>
31-
regExpMatchedStep(
32-
{
33-
regExp:
34-
/^I have the fingerprint for my device in `(?<storageName>[^`]+)`$/,
35-
schema: Type.Object({
36-
storageName: Type.String({ minLength: 1 }),
37-
}),
38-
},
39-
async ({ match: { storageName }, log: { progress }, context }) => {
40-
const now = new Date()
41-
const fingerprint = fingerprintGenerator(
42-
parseInt(
43-
`${(now.getFullYear() - 2000).toString()}${getCurrentWeekNumber()}`,
44-
10,
45-
),
46-
)()
47-
progress(`Fingerprint: ${fingerprint}`)
48-
context[storageName] = fingerprint
49-
const deviceId = `oob-${IMEI()}`
50-
progress(`DeviceID: ${deviceId}`)
51-
52-
await httpApiMock.response(
53-
`GET ${describeOOBDeviceAPIBasePath}?fingerprint=${fingerprint}`,
54-
{
55-
status: 200,
56-
headers: new Headers({
57-
'content-type': 'application/json; charset=utf-8',
58-
}),
59-
body: JSON.stringify({
60-
'@context':
61-
'https://github.com/hello-nrfcloud/proto/deviceIdentity',
62-
id: deviceId,
63-
model: 'PCA20035+solar',
64-
}),
65-
},
66-
)
67-
},
68-
)
6912

7013
const publishDeviceMessage = (iotData: IoTDataPlaneClient) =>
7114
regExpMatchedStep(
@@ -97,13 +40,6 @@ const publishDeviceMessage = (iotData: IoTDataPlaneClient) =>
9740

9841
export const steps = ({
9942
iotData,
100-
httpApiMock,
101-
describeOOBDeviceAPIBasePath,
10243
}: {
10344
iotData: IoTDataPlaneClient
104-
httpApiMock: HttpAPIMock
105-
describeOOBDeviceAPIBasePath: string
106-
}): Array<StepRunner<Record<string, any>>> => [
107-
publishDeviceMessage(iotData),
108-
oobDeviceWithFingerprint(httpApiMock, describeOOBDeviceAPIBasePath),
109-
]
45+
}): Array<StepRunner<Record<string, any>>> => [publishDeviceMessage(iotData)]

features/OOBMapShare.feature.md

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
---
22
exampleContext:
3-
fingerprint: 92b.y7i24q
43
deviceId: oob-352656108602296
54
publicDeviceId: outfling-swanherd-attaghan
6-
describeOOBDeviceAPI: "https://oob-device.lambda-url.eu-west-1.on.aws/"
75
API: "https://iiet67bnlmbtuhiblik4wcy4ni0oujot.execute-api.eu-west-1.amazonaws.com/2024-04-12"
86
ts: 1694503339523
97
tsISO: 2023-09-12T00:00:00.000Z
@@ -15,40 +13,18 @@ exampleContext:
1513
> compared with other devices and can be observed by users without needing to
1614
> know the fingerprint.
1715
>
18-
> Note: Users need to know the fingerprint of the device in order to prevent
19-
> them sharing devices they don't have access to by guessing the IMEI.
20-
>
2116
> This works for the Thingy:91 X because they have credentials that already tie
2217
> them to the nRF Cloud account that is used by `hello.nrfcloud.com/map`. The
2318
> only thing the user needs to do is to consent to the sharing.
2419
2520
## Background
2621

27-
Given I have the fingerprint for my device in `fingerprint`
28-
29-
And I have a random email in `email`
30-
31-
## Get the device ID from `hello.nrfcloud.com`
32-
33-
> Query the `hello.nrfcloud.com` backend to retrieve the device ID using the
34-
> fingerprint
35-
36-
When I `GET` to `${describeOOBDeviceAPI}?fingerprint=${fingerprint}`
37-
38-
Then I should receive a `https://github.com/hello-nrfcloud/proto/deviceIdentity`
39-
response
40-
41-
And the last response should match
22+
> The `deviceId` and `model` is provided in a link from the device page on
23+
> `hello.nrfcloud.com`.
4224
43-
```json
44-
{
45-
"model": "PCA20035+solar"
46-
}
47-
```
48-
49-
And I store `id` of the last response into `deviceId`
25+
Given I have a random device ID in `deviceId`
5026

51-
And I store `model` of the last response into `model`
27+
And I have a random email in `email`
5228

5329
## Share the device
5430

@@ -59,7 +35,7 @@ When I `POST` to `${API}/share` with
5935
```json
6036
{
6137
"deviceId": "${deviceId}",
62-
"model": "${model}",
38+
"model": "PCA20035+solar",
6339
"email": "${email}"
6440
}
6541
```

0 commit comments

Comments
 (0)