Skip to content

Commit

Permalink
- Before re-registering a device in tests, make sure it has at least …
Browse files Browse the repository at this point in the history
…one recording so that the previous device is set inactive rather than deleted.
  • Loading branch information
hardiesoft committed Oct 15, 2024
1 parent 0a2afbb commit 677bbcc
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { NOT_NULL_STRING } from "@commands/constants";
import { getTestName } from "@commands/names";
import { getCreds } from "@commands/server";
import ApiDeviceResponse = Cypress.ApiDeviceResponse;
import { DeviceType, HttpStatusCode } from "@typedefs/api/consts";
import {
DeviceType,
HttpStatusCode,
RecordingType,
} from "@typedefs/api/consts";
import { DeviceHistoryEntry } from "@commands/types";
import { TestCreateExpectedHistoryEntry } from "@commands/api/device";

Expand Down Expand Up @@ -38,6 +42,13 @@ describe("Device reregister", () => {
groupId: getCreds("RR_group1").id,
};
});
cy.log("Add a recording so that old device isn't deleted when renamed");
cy.apiRecordingAdd(
"RR_cam1",
{ type: RecordingType.ThermalRaw },
"oneframe.cptv",
"raRecording1"
);

//re-register camera & store device details
cy.apiDeviceReregister("RR_cam1", "RR_cam1b", "RR_group1").then(() => {
Expand Down Expand Up @@ -129,6 +140,14 @@ describe("Device reregister", () => {
cy.log("create second group");
cy.testCreateUserAndGroup("RR_user2b", "RR_group2b");

cy.log("Add a recording so that old device isn't deleted when renamed");
cy.apiRecordingAdd(
"RR_cam2",
{ type: RecordingType.ThermalRaw },
"oneframe.cptv",
"raRecording1"
);

cy.log("re-register camera to 2nd group & store device details");
cy.apiDeviceReregister("RR_cam2", "RR_cam2", "RR_group2b").then(() => {
expectedDevice2b = {
Expand Down Expand Up @@ -168,6 +187,14 @@ describe("Device reregister", () => {
}
);

cy.log("Add a recording so that old device isn't deleted when renamed");
cy.apiRecordingAdd(
"RR_cam3",
{ type: RecordingType.ThermalRaw },
"oneframe.cptv",
"raRecording1"
);

cy.log("create second group");
cy.testCreateUserAndGroup("RR_user3b", "RR_group3b");

Expand Down
8 changes: 7 additions & 1 deletion integration-tests/cypress/e2e/api/batch-1/devices/devices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getTestName } from "@commands/names";
import { makeAuthorizedRequest, v1ApiPath, getCreds } from "@commands/server";
import ApiDeviceResponse = Cypress.ApiDeviceResponse;
import { DeviceType } from "@typedefs/api/consts";
import { DeviceType, RecordingType } from "@typedefs/api/consts";

describe("Devices list", () => {
const superuser = getCreds("superuser")["email"];
Expand Down Expand Up @@ -69,6 +69,12 @@ describe("Devices list", () => {

//reregistered device
cy.testCreateUserGroupAndDevice(user3, group3, camera3);
cy.log("Add a recording so that old device isn't deleted when renamed");
cy.apiRecordingAdd(
camera3,
{ type: RecordingType.ThermalRaw },
"oneframe.cptv"
);
cy.apiDeviceReregister(camera3, camera4, group3).then(() => {
expectedDevice3AdminView = {
id: getCreds(camera3).id,
Expand Down
16 changes: 13 additions & 3 deletions integration-tests/cypress/e2e/api/batch-1/groups/groups_devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getCreds } from "@commands/server";

import { NOT_NULL_STRING } from "@commands/constants";
import ApiDeviceResponse = Cypress.ApiDeviceResponse;
import { DeviceType, HttpStatusCode } from "@typedefs/api/consts";
import {
DeviceType,
HttpStatusCode,
RecordingType,
} from "@typedefs/api/consts";

describe("Groups - get devices for group", () => {
const NOT_ADMIN = false;
Expand Down Expand Up @@ -126,6 +130,12 @@ describe("Groups - get devices for group", () => {
});

cy.log("Reregister the camera, making the old camera inactive");
cy.apiRecordingAdd(
"gdCam4a",
{ type: RecordingType.ThermalRaw },
"oneframe.cptv",
"raRecording1"
);
cy.apiDeviceReregister("gdCam4a", "gdCam4b", "gdGroup4").then(() => {
expectedGroupDevice4b = {
id: getCreds("gdCam4b").id,
Expand All @@ -135,7 +145,7 @@ describe("Groups - get devices for group", () => {
groupId: getCreds("gdGroup4").id,
active: true,
admin: true,
type: DeviceType.Unknown,
type: DeviceType.Thermal,
lastConnectionTime: NOT_NULL_STRING,
isHealthy: true,
};
Expand All @@ -147,7 +157,7 @@ describe("Groups - get devices for group", () => {
groupId: getCreds("gdGroup4").id,
active: true,
admin: true,
type: DeviceType.Unknown,
type: DeviceType.Thermal,
lastConnectionTime: NOT_NULL_STRING,
isHealthy: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,88 @@ describe("Recordings (thermal): add, get, delete", () => {
const recording1 = TestCreateRecordingData(templateRecording);
let expectedRecording1: ApiThermalRecordingResponse;

cy.log("Rename/reregister device");
cy.apiDeviceReregister("raCamera1", "raCamera1-renamed", "raGroup").then(
() => {
cy.log(
"Add a recording to device to be re-registered so that the old device is set inactive, not deleted"
);
cy.apiRecordingAddOnBehalfUsingDevice(
"raGroupAdmin",
"raCamera1",
recording1,
"raRecording1"
).then(() => {
cy.log("Rename/reregister device");
cy.apiDeviceReregister("raCamera1", "raCamera1-renamed", "raGroup").then(
() => {
cy.log("Add recording as group member");
cy.apiRecordingAddOnBehalfUsingDevice(
"raGroupAdmin",
"raCamera1",
recording1,
"raRecording1"
).then(() => {
expectedRecording1 = TestCreateExpectedRecordingData(
templateExpectedRecording,
"raRecording1",
"raCamera1",
"raGroup",
null,
recording1
);
cy.log("Check recording can be viewed correctly");
cy.apiRecordingCheck(
"raGroupMember",
"raRecording1",
expectedRecording1,
EXCLUDE_IDS
);
});

cy.log("Delete recording");
cy.apiRecordingDelete("raGroupMember", "raRecording1");

cy.log("Check recording no longer exists");
cy.apiRecordingCheck(
"raGroupMember",
"raRecording1",
undefined,
[],
HttpStatusCode.Forbidden
);
}
);
});
});

it("Group member can add recordings by device on behalf - for inactive device", () => {
// NOTE: This test requires the previous test to also pass.
const recording1 = TestCreateRecordingData(templateRecording);
let expectedRecording1: ApiThermalRecordingResponse;
cy.log(
"Add a recording to device to be re-registered so that the old device is set inactive, not deleted"
);
cy.apiRecordingAddOnBehalfUsingDevice(
"raGroupAdmin",
"raCamera1-renamed",
recording1,
"raRecording1"
).then(() => {
cy.log("Rename/reregister device");
cy.apiDeviceReregister(
"raCamera1-renamed",
"raCamera1-renamed2",
"raGroup"
).then(() => {
cy.log("Add recording as group member");
cy.apiRecordingAddOnBehalfUsingDevice(
"raGroupAdmin",
"raCamera1",
"raGroupMember",
"raCamera1-renamed",
recording1,
"raRecording1"
).then(() => {
expectedRecording1 = TestCreateExpectedRecordingData(
templateExpectedRecording,
"raRecording1",
"raCamera1",
"raCamera1-renamed",
"raGroup",
null,
recording1
Expand All @@ -368,55 +436,7 @@ describe("Recordings (thermal): add, get, delete", () => {
[],
HttpStatusCode.Forbidden
);
}
);
});

it("Group member can add recordings by device on behalf - for inactive device", () => {
// NOTE: This test requires the previous test to also pass.
const recording1 = TestCreateRecordingData(templateRecording);
let expectedRecording1: ApiThermalRecordingResponse;
cy.log("Rename/reregister device");
cy.apiDeviceReregister(
"raCamera1-renamed",
"raCamera1-renamed2",
"raGroup"
).then(() => {
cy.log("Add recording as group member");
cy.apiRecordingAddOnBehalfUsingDevice(
"raGroupMember",
"raCamera1-renamed",
recording1,
"raRecording1"
).then(() => {
expectedRecording1 = TestCreateExpectedRecordingData(
templateExpectedRecording,
"raRecording1",
"raCamera1-renamed",
"raGroup",
null,
recording1
);
cy.log("Check recording can be viewed correctly");
cy.apiRecordingCheck(
"raGroupMember",
"raRecording1",
expectedRecording1,
EXCLUDE_IDS
);
});

cy.log("Delete recording");
cy.apiRecordingDelete("raGroupMember", "raRecording1");

cy.log("Check recording no longer exists");
cy.apiRecordingCheck(
"raGroupMember",
"raRecording1",
undefined,
[],
HttpStatusCode.Forbidden
);
});
});

Expand Down

0 comments on commit 677bbcc

Please sign in to comment.