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

#1367 add columns to sites list view #223

Merged
merged 14 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 13 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
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions udmif/api/src/__tests__/common/SearchOptionsValidator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { validateSearchOptions, validateDistinctSearchOptions } from '../../common/SearchOptionsValidator';

describe('SearchOptionsValidator.validateSearchOptions', () => {
test('defaults offset if not provided', () => {
expect(validateSearchOptions({ batchSize: 100 })).toEqual({ batchSize: 100, offset: 0 });
});

test.each([
[0, 0],
[999, 999],
[1000, 1000],
[1001, 1000],
])('limit is reduced to 1000 if a value greater than 1000', async (batchSize, expected) => {
expect(validateSearchOptions({ batchSize })).toEqual({ batchSize: expected, offset: 0 });
[null, 0],
[undefined, 0],
])('offset defaults to 0 when not supplied', async (offset, expected) => {
expect(validateSearchOptions({ offset }).offset).toEqual(expected);
});

test('offset still defaults to 0 when no searchOptions are supplied', () => {
expect(validateSearchOptions().offset).toEqual(0);
});
});

Expand Down
2 changes: 1 addition & 1 deletion udmif/api/src/__tests__/dao/DAO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('DAO', () => {
});

test('getAll', async () => {
const insertedDeviceDocument: Device = { name: 'device-1', site: 'LOC' };
const insertedDeviceDocument: Device = { id: 'd-id-1', name: 'device-1', site: 'LOC' };

deviceCollection.insertOne(insertedDeviceDocument);

Expand Down
25 changes: 21 additions & 4 deletions udmif/api/src/__tests__/device/MockDeviceDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLDataSource } from 'apollo-datasource-graphql/dist/GraphQLDataSource';
import { SearchOptions } from '../../common/model';
import { sum } from 'lodash';
import { Device, DevicesResponse, Point } from '../../device/model';
import { createDevices } from './data';

Expand All @@ -12,16 +12,16 @@ export default class MockDeviceDataSource extends GraphQLDataSource<object> {
super.initialize(config);
}

async getDevices(searchOptions: SearchOptions): Promise<DevicesResponse> {
async getDevices(): Promise<DevicesResponse> {
const devices: Device[] = createDevices(30);
return { devices, totalCount: 30, totalFilteredCount: 10 };
}

async getDevice(id: string): Promise<Device> {
async getDevice(): Promise<Device> {
return createDevices(1)[0];
}

async getPoints(deviceId: string): Promise<Point[]> {
async getPoints(): Promise<Point[]> {
return createDevices(1)[0].points;
}

Expand All @@ -48,4 +48,21 @@ export default class MockDeviceDataSource extends GraphQLDataSource<object> {
.map((d) => d.section)
.sort();
}

async getDevicesBySite(siteName: string): Promise<DevicesResponse> {
const response = await this.getDevices();

return {
...response,
devices: response.devices.filter((d) => d.site === siteName),
};
}

async getDeviceErrorsCountBySite(siteName: string): Promise<number> {
const { devices } = await this.getDevicesBySite(siteName);

return devices.reduce((n: number, device: Device) => {
return sum([n, device.validation?.errors.length]);
}, 0);
}
}
62 changes: 31 additions & 31 deletions udmif/api/src/__tests__/device/__snapshots__/resolve.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Object {
],
"section": "SIN-MBC1",
"serialNumber": "serialNo-1",
"site": "SG-SIN-MBC1",
"site": "LOC-1",
"tags": Array [],
},
},
Expand All @@ -77,7 +77,7 @@ Object {
"name": "CDS-1",
"operational": true,
"section": "SIN-MBC1",
"site": "SG-SIN-MBC1",
"site": "LOC-1",
"tags": Array [],
},
Object {
Expand All @@ -88,7 +88,7 @@ Object {
"name": "AHU-2",
"operational": true,
"section": "SIN-MBC2",
"site": "SG-SIN-MBC2",
"site": "SITE-2",
"tags": Array [],
},
Object {
Expand All @@ -99,7 +99,7 @@ Object {
"name": "CDS-3",
"operational": false,
"section": "SIN-MBC3",
"site": "SG-SIN-MBC3",
"site": "LOC-3",
"tags": Array [],
},
Object {
Expand All @@ -110,7 +110,7 @@ Object {
"name": "AHU-4",
"operational": true,
"section": "SIN-MBC4",
"site": "SG-SIN-MBC4",
"site": "SITE-4",
"tags": Array [],
},
Object {
Expand All @@ -121,7 +121,7 @@ Object {
"name": "CDS-5",
"operational": true,
"section": "SIN-MBC5",
"site": "SG-SIN-MBC5",
"site": "LOC-5",
"tags": Array [],
},
Object {
Expand All @@ -132,7 +132,7 @@ Object {
"name": "AHU-6",
"operational": false,
"section": "SIN-MBC6",
"site": "SG-SIN-MBC6",
"site": "SITE-6",
"tags": Array [],
},
Object {
Expand All @@ -143,7 +143,7 @@ Object {
"name": "CDS-7",
"operational": true,
"section": "SIN-MBC7",
"site": "SG-SIN-MBC7",
"site": "LOC-7",
"tags": Array [],
},
Object {
Expand All @@ -154,7 +154,7 @@ Object {
"name": "AHU-8",
"operational": true,
"section": "SIN-MBC8",
"site": "SG-SIN-MBC8",
"site": "SITE-8",
"tags": Array [],
},
Object {
Expand All @@ -165,7 +165,7 @@ Object {
"name": "CDS-9",
"operational": false,
"section": "SIN-MBC9",
"site": "SG-SIN-MBC9",
"site": "LOC-9",
"tags": Array [],
},
Object {
Expand All @@ -176,7 +176,7 @@ Object {
"name": "AHU-10",
"operational": true,
"section": "SIN-MBC10",
"site": "SG-SIN-MBC10",
"site": "SITE-10",
"tags": Array [],
},
Object {
Expand All @@ -187,7 +187,7 @@ Object {
"name": "CDS-11",
"operational": true,
"section": "SIN-MBC11",
"site": "SG-SIN-MBC11",
"site": "LOC-11",
"tags": Array [],
},
Object {
Expand All @@ -198,7 +198,7 @@ Object {
"name": "AHU-12",
"operational": false,
"section": "SIN-MBC12",
"site": "SG-SIN-MBC12",
"site": "SITE-12",
"tags": Array [],
},
Object {
Expand All @@ -209,7 +209,7 @@ Object {
"name": "CDS-13",
"operational": true,
"section": "SIN-MBC13",
"site": "SG-SIN-MBC13",
"site": "LOC-13",
"tags": Array [],
},
Object {
Expand All @@ -220,7 +220,7 @@ Object {
"name": "AHU-14",
"operational": true,
"section": "SIN-MBC14",
"site": "SG-SIN-MBC14",
"site": "SITE-14",
"tags": Array [],
},
Object {
Expand All @@ -231,7 +231,7 @@ Object {
"name": "CDS-15",
"operational": false,
"section": "SIN-MBC15",
"site": "SG-SIN-MBC15",
"site": "LOC-15",
"tags": Array [],
},
Object {
Expand All @@ -242,7 +242,7 @@ Object {
"name": "AHU-16",
"operational": true,
"section": "SIN-MBC16",
"site": "SG-SIN-MBC16",
"site": "SITE-16",
"tags": Array [],
},
Object {
Expand All @@ -253,7 +253,7 @@ Object {
"name": "CDS-17",
"operational": true,
"section": "SIN-MBC17",
"site": "SG-SIN-MBC17",
"site": "LOC-17",
"tags": Array [],
},
Object {
Expand All @@ -264,7 +264,7 @@ Object {
"name": "AHU-18",
"operational": false,
"section": "SIN-MBC18",
"site": "SG-SIN-MBC18",
"site": "SITE-18",
"tags": Array [],
},
Object {
Expand All @@ -275,7 +275,7 @@ Object {
"name": "CDS-19",
"operational": true,
"section": "SIN-MBC19",
"site": "SG-SIN-MBC19",
"site": "LOC-19",
"tags": Array [],
},
Object {
Expand All @@ -286,7 +286,7 @@ Object {
"name": "AHU-20",
"operational": true,
"section": "SIN-MBC20",
"site": "SG-SIN-MBC20",
"site": "SITE-20",
"tags": Array [],
},
Object {
Expand All @@ -297,7 +297,7 @@ Object {
"name": "CDS-21",
"operational": false,
"section": "SIN-MBC21",
"site": "SG-SIN-MBC21",
"site": "LOC-21",
"tags": Array [],
},
Object {
Expand All @@ -308,7 +308,7 @@ Object {
"name": "AHU-22",
"operational": true,
"section": "SIN-MBC22",
"site": "SG-SIN-MBC22",
"site": "SITE-22",
"tags": Array [],
},
Object {
Expand All @@ -319,7 +319,7 @@ Object {
"name": "CDS-23",
"operational": true,
"section": "SIN-MBC23",
"site": "SG-SIN-MBC23",
"site": "LOC-23",
"tags": Array [],
},
Object {
Expand All @@ -330,7 +330,7 @@ Object {
"name": "AHU-24",
"operational": false,
"section": "SIN-MBC24",
"site": "SG-SIN-MBC24",
"site": "SITE-24",
"tags": Array [],
},
Object {
Expand All @@ -341,7 +341,7 @@ Object {
"name": "CDS-25",
"operational": true,
"section": "SIN-MBC25",
"site": "SG-SIN-MBC25",
"site": "LOC-25",
"tags": Array [],
},
Object {
Expand All @@ -352,7 +352,7 @@ Object {
"name": "AHU-26",
"operational": true,
"section": "SIN-MBC26",
"site": "SG-SIN-MBC26",
"site": "SITE-26",
"tags": Array [],
},
Object {
Expand All @@ -363,7 +363,7 @@ Object {
"name": "CDS-27",
"operational": false,
"section": "SIN-MBC27",
"site": "SG-SIN-MBC27",
"site": "LOC-27",
"tags": Array [],
},
Object {
Expand All @@ -374,7 +374,7 @@ Object {
"name": "AHU-28",
"operational": true,
"section": "SIN-MBC28",
"site": "SG-SIN-MBC28",
"site": "SITE-28",
"tags": Array [],
},
Object {
Expand All @@ -385,7 +385,7 @@ Object {
"name": "CDS-29",
"operational": true,
"section": "SIN-MBC29",
"site": "SG-SIN-MBC29",
"site": "LOC-29",
"tags": Array [],
},
Object {
Expand All @@ -396,7 +396,7 @@ Object {
"name": "AHU-30",
"operational": false,
"section": "SIN-MBC30",
"site": "SG-SIN-MBC30",
"site": "SITE-30",
"tags": Array [],
},
],
Expand Down
Loading