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

fix: mock sitewise sdk in component tests #56

Merged
merged 1 commit into from
Feb 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector';
import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const barChartSpecPage = async (propOverrides: Partial<Components.IotBarChart> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/iot-kpi/iot-kpi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time
import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const kpiSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CustomHTMLElement } from '../../testing/types';
import { initialize, query, SiteWiseDataStreamQuery } from '@iot-app-kit/core';
import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const lineChartSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createMockSiteWiseSDK, initialize, IoTAppKitInitInputs } from '@iot-app-kit/core';
import { initialize, IoTAppKitInitInputs, createMockSiteWiseSDK } from '@iot-app-kit/core';
import { newSpecPage } from '@stencil/core/testing';
import { IotResourceExplorer } from './iot-resource-explorer';
import { Components } from '../../components.d';
Expand All @@ -7,15 +7,15 @@ import { update } from '../../testing/update';
import { ResourceExplorerQuery } from './types';
import flushPromises from 'flush-promises';
import { mocklistAssetsResponse } from '../../testing/mocks/data/listAssetsResponse';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const resourceExplorerSpec = async (
propOverrides: Partial<Components.IotResourceExplorer>,
appKitInitOverrides: Partial<IoTAppKitInitInputs> = {}
) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
...appKitInitOverrides,
});
const page = await newSpecPage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createMockSiteWiseSDK, initialize, IoTAppKitInitInputs } from '@iot-app-kit/core';
import { initialize, IoTAppKitInitInputs, createMockSiteWiseSDK } from '@iot-app-kit/core';
import * as core from '@iot-app-kit/core';
import { newSpecPage } from '@stencil/core/testing';
import { SitewiseResourceExplorer } from './sitewise-resource-explorer';
Expand All @@ -7,6 +7,7 @@ import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { SitewiseAssetResource } from './types';
import flushPromises from 'flush-promises';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';
import { mocklistAssetsResponse } from '../../testing/mocks/data/listAssetsResponse';

const columnDefinitions = [
Expand All @@ -24,8 +25,7 @@ const sitewiseResourceExplorerSpec = async (
) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
...appKitInitOverrides,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time
import { CustomHTMLElement } from '../../testing/types';
import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const scatterChartSpecPage = async (propOverrides: Partial<Components.IotScatterChart> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector';
import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const statusGridSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector';
import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const statusTimelineSpecPage = async (propOverrides: Partial<Components.IotStatusTimeline> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector';
import { CustomHTMLElement } from '../../testing/types';
import { update } from '../../testing/update';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const viewport: MinimalLiveViewport = {
duration: 1000,
Expand All @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = {
const tableSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
});
appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
initialize,
SiteWiseDataStreamQuery,
IoTAppKitInitInputs,
createMockSiteWiseSDK,
query,
createMockSiteWiseSDK,
} from '@iot-app-kit/core';
import { IotTimeSeriesConnector } from './iot-time-series-connector';
import { createMockSource } from '../../testing/createMockSource';
Expand All @@ -16,6 +16,7 @@ import { DATA_STREAM, DATA_STREAM_2 } from '../../testing/mockWidgetProperties';
import { toSiteWiseAssetProperty } from '../../testing/dataStreamId';
import { Components } from '../../components';
import { DescribeAssetResponse, DescribeAssetModelResponse } from '@aws-sdk/client-iotsitewise';
import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK';

const createAssetResponse = ({
assetId,
Expand Down Expand Up @@ -69,8 +70,7 @@ const viewport: MinimalLiveViewport = {
const initializeAppKit = (appKitInitOverrides?: Partial<IoTAppKitInitInputs>) => {
const appKit = initialize({
registerDataSources: false,
awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' },
awsRegion: 'test',
iotSiteWiseClient: mockSiteWiseSDK,
...appKitInitOverrides,
});

Expand Down
32 changes: 32 additions & 0 deletions packages/components/src/testing/mocks/siteWiseSDK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
createMockSiteWiseSDK,
createAssetResponse,
createAssetModelResponse,
ASSET_PROPERTY_VALUE_HISTORY,
} from '@iot-app-kit/core';

const PROPERTY_ID = 'some-property-id';
const ASSET_MODEL_ID = 'some-asset-model-id';
const PROPERTY_NAME = 'some-property-name';

const getAssetPropertyValueHistory = jest.fn().mockResolvedValue(ASSET_PROPERTY_VALUE_HISTORY);
const describeAsset = jest
.fn()
.mockImplementation(({ assetId }) =>
Promise.resolve(createAssetResponse({ assetId: assetId as string, assetModelId: ASSET_MODEL_ID }))
);
const describeAssetModel = jest.fn().mockImplementation(({ assetModelId }) =>
Promise.resolve(
createAssetModelResponse({
assetModelId: assetModelId as string,
propertyId: PROPERTY_ID,
propertyName: PROPERTY_NAME,
})
)
);

export const mockSiteWiseSDK = createMockSiteWiseSDK({
describeAsset,
describeAssetModel,
getAssetPropertyValueHistory,
});
3 changes: 1 addition & 2 deletions packages/core/src/data-module/IotAppKitDataModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { DataPoint } from '@synchro-charts/core';
import { TimeSeriesDataRequest, TimeSeriesDataRequestSettings } from './data-cache/requestTypes';
import { DataStreamsStore, DataStreamStore } from './data-cache/types';
import * as caching from './data-cache/caching/caching';
import { createMockSiteWiseDataSource } from '../testing/mock-data-source/data-source';
import { createMockSiteWiseDataSource } from '../iotsitewise/__mocks__/data-source';
import { HOUR_IN_MS, MINUTE_IN_MS, MONTH_IN_MS, SECOND_IN_MS } from '../common/time';
import { IotAppKitDataModule } from './IotAppKitDataModule';

import { SITEWISE_DATA_SOURCE } from '../iotsitewise/time-series-data/data-source';
import { SiteWiseDataStreamQuery } from '../iotsitewise/time-series-data/types';
import { toDataStreamId, toSiteWiseAssetProperty } from '../iotsitewise/time-series-data/util/dataStreamId';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './data-module/index';
export * from './asset-modules/index';
export * from './iotAppKit';
export * from './iotsitewise/__mocks__/iotsitewiseSDK';
export * from './module-namespace';
export * from './query-namespace';
export * from './iotsitewise/time-series-data/provider';
export * from './testing'; // @todo: build as a separate bundle
8 changes: 4 additions & 4 deletions packages/core/src/iotsitewise/__mocks__/assetPropertyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
GetAssetPropertyAggregatesResponse,
GetAssetPropertyValueHistoryResponse,
GetAssetPropertyValueResponse,
Quality
} from "@aws-sdk/client-iotsitewise";
Quality,
} from '@aws-sdk/client-iotsitewise';

/**
* Mocks, related to a SiteWise Assert property value
Expand Down Expand Up @@ -99,6 +99,6 @@ export const samplePropertyValue: AssetPropertyValue = {
quality: Quality.GOOD,
timestamp: {
timeInSeconds: 100,
offsetInNanos: 100
}
offsetInNanos: 100,
},
};
6 changes: 6 additions & 0 deletions packages/core/src/iotsitewise/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './asset';
export * from './assetModel';
export * from './assetPropertyValue';
export * from './iotsitewiseSDK';
export * from './mockWidgetProperties';
export * from './data-source';
2 changes: 1 addition & 1 deletion packages/core/src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './wait';
export * from '../iotsitewise/__mocks__';
1 change: 0 additions & 1 deletion packages/core/src/testing/mock-data-source/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/src/testing/wait.ts

This file was deleted.