Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change separator for assets and devices IDs #63

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions features/AssetController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Feature: Device Manager asset controller
| index | "tenant-kuzzle" |
| body.type | "outils" |
| body.model | "PERFO" |
| body.reference | "asset-01" |
Then The document "tenant-kuzzle":"assets":"outils_PERFO_asset-01" exists
| body.reference | "asset_01" |
Then The document "tenant-kuzzle":"assets":"outils-PERFO-asset_01" exists
When I successfully execute the action "device-manager/asset":"update" with args:
| index | "tenant-kuzzle" |
| _id | "outils_PERFO_asset-01" |
| _id | "outils-PERFO-asset_01" |
| body.metadata.foobar | 42 |
And I successfully execute the action "device-manager/asset":"delete" with args:
| index | "tenant-kuzzle" |
| _id | "outils_PERFO_asset-01" |
Then The document "tenant-kuzzle":"assets":"outils_PERFO_asset-01" does not exists
| _id | "outils-PERFO-asset_01" |
Then The document "tenant-kuzzle":"assets":"outils-PERFO-asset_01" does not exists
148 changes: 74 additions & 74 deletions features/DeviceController.feature

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions features/PayloadController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Payloads Controller
| deviceEUI | "12345" |
| register55 | 23.3 |
| batteryLevel | 0.8 |
Then The document "device-manager":"devices":"DummyTemp_12345" content match:
Then The document "device-manager":"devices":"DummyTemp-12345" content match:
| reference | "12345" |
| model | "DummyTemp" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
Expand All @@ -24,7 +24,7 @@ Feature: Payloads Controller
| deviceEUI | "12345" |
| register55 | 42.2 |
| batteryLevel | 0.7 |
Then The document "device-manager":"devices":"DummyTemp_12345" content match:
Then The document "device-manager":"devices":"DummyTemp-12345" content match:
| reference | "12345" |
| model | "DummyTemp" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
Expand All @@ -49,7 +49,7 @@ Feature: Payloads Controller
| location.lat | 42.2 |
| location.lon | 2.42 |
| location.accu | 2100 |
Then The document "device-manager":"devices":"DummyTempPosition_12345" content match:
Then The document "device-manager":"devices":"DummyTempPosition-12345" content match:
| reference | "12345" |
| model | "DummyTempPosition" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
Expand All @@ -69,15 +69,15 @@ Feature: Payloads Controller
| deviceEUI | "12345" |
| register55 | 23.3 |
| batteryLevel | 0.8 |
Then The document "device-manager":"devices":"DummyTemp_12345" content match:
Then The document "device-manager":"devices":"DummyTemp-12345" content match:
| qos.registerEnriched | true |
| qos.updateEnriched | "_UNDEFINED_" |
# Update
When I successfully receive a "dummy-temp" payload with:
| deviceEUI | "12345" |
| register55 | 23.3 |
| batteryLevel | 0.8 |
Then The document "device-manager":"devices":"DummyTemp_12345" content match:
Then The document "device-manager":"devices":"DummyTemp-12345" content match:
| qos.registerEnriched | true |
| qos.updateEnriched | true |

Expand All @@ -98,50 +98,50 @@ Feature: Payloads Controller

Scenario: Propagate device to tenant index
When I successfully receive a "dummy-temp" payload with:
| deviceEUI | "attached-ayse-unlinked" |
| deviceEUI | "attached_ayse_unlinked" |
| register55 | 42.2 |
| batteryLevel | 0.4 |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
Then The document "device-manager":"devices":"DummyTemp-attached_ayse_unlinked" content match:
| tenantId | "tenant-ayse" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
| measures.temperature.payloadUuid | "_STRING_" |
| measures.temperature.degree | 42.2 |
| qos.battery | 40 |
And The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
And The document "tenant-ayse":"devices":"DummyTemp-attached_ayse_unlinked" content match:
| tenantId | "tenant-ayse" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
| measures.temperature.payloadUuid | "_STRING_" |
| measures.temperature.degree | 42.2 |
| qos.battery | 40 |
And I should receive a result matching:
| device._id | "DummyTemp_attached-ayse-unlinked" |
| device._id | "DummyTemp-attached_ayse_unlinked" |
| asset | null |
| tenantId | "tenant-ayse" |

Scenario: Propagate device measures to asset
Given I successfully execute the action "device-manager/device":"linkAsset" with args:
| _id | "DummyTemp_attached-ayse-unlinked" |
| _id | "DummyTemp-attached_ayse_unlinked" |
| assetId | "PERFO-unlinked" |
When I successfully receive a "dummy-temp" payload with:
| deviceEUI | "attached-ayse-unlinked" |
| deviceEUI | "attached_ayse_unlinked" |
| register55 | 42.2 |
| batteryLevel | 0.4 |
Then The document "device-manager":"devices":"DummyTemp_attached-ayse-unlinked" content match:
Then The document "device-manager":"devices":"DummyTemp-attached_ayse_unlinked" content match:
| tenantId | "tenant-ayse" |
| assetId | "PERFO-unlinked" |
Then The document "tenant-ayse":"devices":"DummyTemp_attached-ayse-unlinked" content match:
Then The document "tenant-ayse":"devices":"DummyTemp-attached_ayse_unlinked" content match:
| tenantId | "tenant-ayse" |
| assetId | "PERFO-unlinked" |
And The document "tenant-ayse":"assets":"PERFO-unlinked" content match:
| measures.temperature.id | "DummyTemp_attached-ayse-unlinked" |
| measures.temperature.reference | "attached-ayse-unlinked" |
| measures.temperature.id | "DummyTemp-attached_ayse_unlinked" |
| measures.temperature.reference | "attached_ayse_unlinked" |
| measures.temperature.model | "DummyTemp" |
| measures.temperature.updatedAt | "_DATE_NOW_" |
| measures.temperature.payloadUuid | "_STRING_" |
| measures.temperature.degree | 42.2 |
| measures.temperature.qos.battery | 40 |
And I should receive a result matching:
| device._id | "DummyTemp_attached-ayse-unlinked" |
| device._id | "DummyTemp-attached_ayse_unlinked" |
| asset._id | "PERFO-unlinked" |
| tenantId | "tenant-ayse" |

2 changes: 1 addition & 1 deletion features/fixtures/devices.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const devices = [];

for (let i = 0; i < 50; i++) {
devices.push({ index: { _id: `DummyTemp_detached-${i}` } });
devices.push({ index: { _id: `DummyTemp-detached-${i}` } });
devices.push({
reference: 'detached',
model: `DummyTemp-${i}`,
Expand Down
10 changes: 5 additions & 5 deletions features/fixtures/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
'device-manager': {
devices: [
...devices,
{ index: { _id: 'DummyTemp_detached' } },
{ index: { _id: 'DummyTemp-detached' } },
{
reference: 'detached',
model: 'DummyTemp',
Expand All @@ -23,9 +23,9 @@ module.exports = {
tenantId: null,
assetId: null
},
{ index: { _id: 'DummyTemp_attached-ayse-unlinked' } },
{ index: { _id: 'DummyTemp-attached_ayse_unlinked' } },
{
reference: 'attached-ayse-unlinked',
reference: 'attached_ayse_unlinked',
model: 'DummyTemp',
measures: {
temperature: {
Expand All @@ -44,9 +44,9 @@ module.exports = {
},
'tenant-ayse': {
devices: [
{ index: { _id: 'DummyTemp_attached-ayse-unlinked' } },
{ index: { _id: 'DummyTemp-attached_ayse_unlinked' } },
{
reference: 'attached-ayse-unlinked',
reference: 'attached_ayse_unlinked',
model: 'DummyTemp',
measures: {
temperature: {
Expand Down
8 changes: 4 additions & 4 deletions features/step_definitions/device-controller-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { devicesTests } = require('../fixtures/devices');
When('I succesfully execute {string}:{string} while exeding documentsWriteCount limit', async function (controller, action) {
const records = [];
for (let i = 0; i < devicesTests.length; i++) {
records.push({ deviceId: `DummyTemp_detached-${i}`, tenantId: 'tenant-kuzzle' });
records.push({ deviceId: `DummyTemp-detached-${i}`, tenantId: 'tenant-kuzzle' });
}


Expand All @@ -21,7 +21,7 @@ When('I succesfully execute {string}:{string} while exeding documentsWriteCount
Then('All devices in {string} {string} have the property {string} to {string}', async function (index, collection, key, value) {
const deviceIds = [];
for (let i = 0; i < devicesTests.length; i++) {
deviceIds.push(`DummyTemp_detached-${i}`);
deviceIds.push(`DummyTemp-detached-${i}`);
}

const { successes, errors } = await this.sdk.document.mGet(index, collection, deviceIds);
Expand All @@ -43,7 +43,7 @@ Then('All devices in {string} {string} have the property {string} to {string}',
Then('All {string} devices documents exists', async function (tenant) {
const deviceIds = [];
for (let i = 0; i < devicesTests.length; i++) {
deviceIds.push(`DummyTemp_detached-${i}`);
deviceIds.push(`DummyTemp-detached-${i}`);
}

const { errors } = await this.sdk.document.mGet(tenant, 'devices', deviceIds);
Expand All @@ -56,7 +56,7 @@ Then('All {string} devices documents exists', async function (tenant) {
Then(/All documents "(.*?)":"(.*?)" (does not)? exists/, async function (index, collection, not) {
const deviceIds = [];
for (let i = 0; i < devicesTests.length; i++) {
deviceIds.push(`DummyTemp_detached-${i}`);
deviceIds.push(`DummyTemp-detached-${i}`);
}

const { successes, errors } = await this.sdk.document.mGet(index, collection, deviceIds);
Expand Down
2 changes: 1 addition & 1 deletion lib/models/BaseAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class BaseAsset {
_source: BaseAssetContent;

constructor (content: BaseAssetContent, _id?: string) {
this._id = _id || `${content.type}_${content.model}_${content.reference}`;
this._id = _id || `${content.type}-${content.model}-${content.reference}`;

this._source = content;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/models/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Device {
_source: DeviceContent;

constructor (content: DeviceContent, _id?: string) {
this._id = _id || `${content.model}_${content.reference}`;
this._id = _id || `${content.model}-${content.reference}`;

this._source = {
qos: {},
Expand Down