Skip to content

Commit

Permalink
tests: more reliable decoder controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebtiz13 committed Dec 2, 2024
1 parent 5084a45 commit 72a4ef2
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 147 deletions.
2 changes: 0 additions & 2 deletions lib/modules/decoder/types/DecoderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ interface DecodersControllerRequest {

export interface ApiDecoderListRequest extends DecodersControllerRequest {
action: "list";

_id: string;
}
export type ApiDecoderListResult = {
decoders: DecoderContent[];
Expand Down
1 change: 1 addition & 0 deletions lib/modules/measure/MeasureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ export class MeasureService extends BaseService {
}
}

console.log("assetContext", assetContext);

Check failure on line 694 in lib/modules/measure/MeasureService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
const measureContent: MeasureContent = {
asset: assetContext,
measuredAt: measurement.measuredAt,
Expand Down
145 changes: 0 additions & 145 deletions tests/scenario/migrated/decoder-decoders-controller.test.ts

This file was deleted.

126 changes: 126 additions & 0 deletions tests/scenario/modules/decoder/Decoders.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { beforeEachTruncateCollections } from "../../../hooks";
import { ApiDecoderListRequest, ApiDecoderListResult } from "../../../../index";

import { useSdk, sendPayloads } from "../../../helpers";

jest.setTimeout(10000);

describe("DecodersController", () => {
const sdk = useSdk();

beforeAll(async () => {
await sdk.connect();

// ? Force provisioning strategy to "auto"
await sdk.query({
controller: "document",
action: "update",
index: "device-manager",
collection: "config",
_id: "plugin--device-manager",
body: { "device-manager": { provisioningStrategy: "auto" } },
});
});

beforeEach(async () => {
await beforeEachTruncateCollections(sdk);
});

afterAll(async () => {
sdk.disconnect();
});

it("Prune payloads collection", async () => {
await sendPayloads(sdk, "dummy-temp", [
{ deviceEUI: "12345", temperature: 23.1, metadata: { color: "RED" } },
]);

await sendPayloads(sdk, "dummy-temp-position", [
{
deviceEUI: "12345",
temperature: 23.3,
location: { lat: 42.2, lon: 2.42, accuracy: 2100 },
battery: 0.8,
},
]);

await sdk.collection.refresh("device-manager", "payloads");

const countBeforePrune = await sdk.query({
controller: "document",
action: "search",
index: "device-manager",
collection: "payloads",
});

expect(countBeforePrune.result).toMatchObject({ total: 2 });

await sdk.query({
controller: "device-manager/decoders",
action: "prunePayloads",
body: { days: 0, deviceModel: "DummyTemp" },
});

await sdk.collection.refresh("device-manager", "payloads");

const countAfterPrune = await sdk.query({
controller: "document",
action: "search",
index: "device-manager",
collection: "payloads",
});

expect(countAfterPrune.result).toMatchObject({ total: 1 });
});

it("provide associated payload action when listing decoder capabilities", async () => {
const { result } = await sdk.query<
ApiDecoderListRequest,
ApiDecoderListResult
>({
controller: "device-manager/decoders",
action: "list",
});

expect(result.decoders).toEqual(
expect.arrayContaining([
expect.objectContaining({
action: "dummy-temp-position",
deviceModel: "DummyTempPosition",
measures: [
{
name: "temperature",
type: "temperature",
},
{
name: "battery",
type: "battery",
},
{
name: "position",
type: "position",
},
],
}),
expect.objectContaining({
action: "dummy-temp",
deviceModel: "DummyTemp",
measures: [
{
name: "temperature",
type: "temperature",
},
{
name: "accelerationSensor",
type: "acceleration",
},
{
name: "battery",
type: "battery",
},
],
}),
]),
);
});
});

0 comments on commit 72a4ef2

Please sign in to comment.