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

#1457 adjust staging data in mongo #232

Merged
merged 4 commits into from
Sep 21, 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
31 changes: 0 additions & 31 deletions udmif/api/src/__tests__/site/__snapshots__/resolve.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Object {
"correctDevicesCount": 1,
"errorDevicesCount": 1,
"extraDevicesCount": 0,
"id": "00000000-0000-0000-0000-0000000001",
"lastValidated": "2022-07-16T18:27:19Z",
"missingDevicesCount": 2,
"name": "LOC-1",
Expand Down Expand Up @@ -59,123 +58,93 @@ Object {
"sites": Object {
"sites": Array [
Object {
"id": "00000000-0000-0000-0000-0000000001",
"name": "LOC-1",
},
Object {
"id": "00000000-0000-0000-0000-0000000002",
"name": "SITE-2",
},
Object {
"id": "00000000-0000-0000-0000-0000000003",
"name": "LOC-3",
},
Object {
"id": "00000000-0000-0000-0000-0000000004",
"name": "SITE-4",
},
Object {
"id": "00000000-0000-0000-0000-0000000005",
"name": "LOC-5",
},
Object {
"id": "00000000-0000-0000-0000-0000000006",
"name": "SITE-6",
},
Object {
"id": "00000000-0000-0000-0000-0000000007",
"name": "LOC-7",
},
Object {
"id": "00000000-0000-0000-0000-0000000008",
"name": "SITE-8",
},
Object {
"id": "00000000-0000-0000-0000-0000000009",
"name": "LOC-9",
},
Object {
"id": "00000000-0000-0000-0000-00000000010",
"name": "SITE-10",
},
Object {
"id": "00000000-0000-0000-0000-00000000011",
"name": "LOC-11",
},
Object {
"id": "00000000-0000-0000-0000-00000000012",
"name": "SITE-12",
},
Object {
"id": "00000000-0000-0000-0000-00000000013",
"name": "LOC-13",
},
Object {
"id": "00000000-0000-0000-0000-00000000014",
"name": "SITE-14",
},
Object {
"id": "00000000-0000-0000-0000-00000000015",
"name": "LOC-15",
},
Object {
"id": "00000000-0000-0000-0000-00000000016",
"name": "SITE-16",
},
Object {
"id": "00000000-0000-0000-0000-00000000017",
"name": "LOC-17",
},
Object {
"id": "00000000-0000-0000-0000-00000000018",
"name": "SITE-18",
},
Object {
"id": "00000000-0000-0000-0000-00000000019",
"name": "LOC-19",
},
Object {
"id": "00000000-0000-0000-0000-00000000020",
"name": "SITE-20",
},
Object {
"id": "00000000-0000-0000-0000-00000000021",
"name": "LOC-21",
},
Object {
"id": "00000000-0000-0000-0000-00000000022",
"name": "SITE-22",
},
Object {
"id": "00000000-0000-0000-0000-00000000023",
"name": "LOC-23",
},
Object {
"id": "00000000-0000-0000-0000-00000000024",
"name": "SITE-24",
},
Object {
"id": "00000000-0000-0000-0000-00000000025",
"name": "LOC-25",
},
Object {
"id": "00000000-0000-0000-0000-00000000026",
"name": "SITE-26",
},
Object {
"id": "00000000-0000-0000-0000-00000000027",
"name": "LOC-27",
},
Object {
"id": "00000000-0000-0000-0000-00000000028",
"name": "SITE-28",
},
Object {
"id": "00000000-0000-0000-0000-00000000029",
"name": "LOC-29",
},
Object {
"id": "00000000-0000-0000-0000-00000000030",
"name": "SITE-30",
},
],
Expand Down
2 changes: 0 additions & 2 deletions udmif/api/src/__tests__/site/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ export function createSites(count: number): Site[] {
let n = 1;

while (n <= count) {
const id = '00000000-0000-0000-0000-000000000' + n;
const name = n % 2 == 0 ? `SITE-${n}` : `LOC-${n}`;
const validation = siteMessage;

sites.push({
id,
name,
validation,
});
Expand Down
4 changes: 1 addition & 3 deletions udmif/api/src/__tests__/site/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const QUERY_SITES = gql`
totalCount
totalFilteredCount
sites {
id
name
}
}
Expand All @@ -32,8 +31,7 @@ const QUERY_SITE_NAMES = gql`

const QUERY_SITE = gql`
query {
site(id: "00000000-0000-0000-0000-0000000001") {
id
site(name: "00000000-0000-0000-0000-0000000001") {
name
totalDevicesCount
correctDevicesCount
Expand Down
10 changes: 5 additions & 5 deletions udmif/api/src/device/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export const resolvers = {
},
level: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
//TODO should these be taken from the device message instead?
return (await siteDS.getSite(device.site)).validation?.devices[device.name]?.status?.level;
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.status?.level;
},
message: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
return (await siteDS.getSite(device.site)).validation?.devices[device.name]?.status?.message;
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.status?.message;
},
details: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
return (await siteDS.getSite(device.site)).validation?.devices[device.name]?.status?.details;
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.status?.details;
},
lastSeen: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
return (await siteDS.getSite(device.site)).validation?.devices[device.name]?.last_seen;
return (await siteDS.getSite(device.site))?.validation?.devices[device.name]?.last_seen;
},
state: async (device: Device, _args, { dataSources: { siteDS } }: ApolloContext) => {
const siteValidationSummary = (await siteDS.getSite(device.site)).validation?.summary;
const siteValidationSummary = (await siteDS.getSite(device.site))?.validation?.summary;

for (const category in siteValidationSummary) {
if (Object.prototype.hasOwnProperty.call(siteValidationSummary, category)) {
Expand Down
4 changes: 2 additions & 2 deletions udmif/api/src/site/SiteDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SiteDataSource extends GraphQLDataSource {
return { sites, totalCount, totalFilteredCount };
}

async getSite(id: string): Promise<Site> {
return this.siteDAO.getOne({ name: id }); //TODO:: for now, lookup by name
async getSite(name: string): Promise<Site> {
return this.siteDAO.getOne({ name });
}
}
3 changes: 1 addition & 2 deletions udmif/api/src/site/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export interface SitesArgs {
}

export interface SiteArgs {
id: string;
name: string;
}

export interface Site {
id: string;
name: string;
validation?: any;
}
4 changes: 2 additions & 2 deletions udmif/api/src/site/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const resolvers = {
sites: (_query, { searchOptions }: SitesArgs, { dataSources: { siteDS } }: ApolloContext) => {
return siteDS.getSites(searchOptions);
},
site: (_query, { id }: SiteArgs, { dataSources: { siteDS } }: ApolloContext) => {
return siteDS.getSite(id);
site: (_query, { name }: SiteArgs, { dataSources: { siteDS } }: ApolloContext) => {
return siteDS.getSite(name);
},
},
Site: {
Expand Down
4 changes: 1 addition & 3 deletions udmif/api/src/site/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ type SitesResponse {
}

type Site {
# ID of the site
id: ID!
# Name of the site
name: String!
# Total number of devices associated to the site
Expand All @@ -36,7 +34,7 @@ type Query {
# Get a list of sites
sites(searchOptions: SearchOptions) : SitesResponse
# Get a site by ID
site(id: ID!): Site
site(name: String!): Site
# Get a list of sites
siteNames(searchOptions: DistinctSearchOptions) : [String!]!
}
12 changes: 9 additions & 3 deletions udmif/web/src/app/graphql/graphql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function ApolloFactory(httpLink: HttpLink, env: EnvService, auth: AuthSer
}
});

const errorLink = onError(({ forward, graphQLErrors, networkError, operation }) => {
const errorLink = onError(({ forward, networkError, operation }) => {
if (networkError) {
if (JSON.stringify(networkError).includes('UNAUTHENTICATED')) {
// Try refreshing the token.
Expand All @@ -54,7 +54,13 @@ export function ApolloFactory(httpLink: HttpLink, env: EnvService, auth: AuthSer

return {
link: ApolloLink.from([errorLink, authLink, httpLink.create({ uri: env.apiUri })]),
cache: new InMemoryCache(),
cache: new InMemoryCache({
typePolicies: {
Site: {
keyFields: ['name'],
},
},
}),
};
}

Expand All @@ -68,4 +74,4 @@ export function ApolloFactory(httpLink: HttpLink, env: EnvService, auth: AuthSer
},
],
})
export class GraphQLModule { }
export class GraphQLModule {}
1 change: 0 additions & 1 deletion udmif/web/src/app/site/site.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('SiteComponent', () => {
let mockNavigationService: jasmine.SpyObj<NavigationService>;
let mockSiteService: jasmine.SpyObj<SiteService>;
let site: Site = {
id: 'site-id-123',
name: 'site one',
totalDevicesCount: 0,
correctDevicesCount: 0,
Expand Down
3 changes: 1 addition & 2 deletions udmif/web/src/app/site/site.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
interface SiteModel {
id: string;
name: string;
totalDevicesCount: number;
correctDevicesCount: number;
Expand All @@ -19,5 +18,5 @@ export type SiteQueryResponse = {
};

export type SiteQueryVariables = {
id: string;
name: string;
};
5 changes: 2 additions & 3 deletions udmif/web/src/app/site/site.gql.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { gql } from 'apollo-angular';

export const GET_SITE = gql`
query GetSite($id: ID!) {
site(id: $id) {
id
query GetSite($name: String!) {
site(name: $name) {
name
totalDevicesCount
correctDevicesCount
Expand Down
3 changes: 1 addition & 2 deletions udmif/web/src/app/site/site.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('SiteService', () => {
it('should return the site', () => {
const mockSiteResponse: SiteQueryResponse = {
site: {
id: '123',
name: 'site one',
totalDevicesCount: 0,
correctDevicesCount: 0,
Expand All @@ -53,7 +52,7 @@ describe('SiteService', () => {

// Assert the correct search options were sent.
expect(op.operation.variables).toEqual({
id: '123',
name: '123',
});

// Respond with mock data, causing Observable to resolve.
Expand Down
4 changes: 2 additions & 2 deletions udmif/web/src/app/site/site.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export class SiteService {

constructor(private apollo: Apollo) {}

getSite(id: string): Observable<ApolloQueryResult<SiteQueryResponse>> {
getSite(name: string): Observable<ApolloQueryResult<SiteQueryResponse>> {
this.siteQuery = this.apollo.watchQuery<SiteQueryResponse, SiteQueryVariables>({
query: GET_SITE,
variables: {
id,
name,
},
});

Expand Down
1 change: 0 additions & 1 deletion udmif/web/src/app/sites/sites.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('SitesComponent', () => {
let refetch: jasmine.Spy;
let sites: Site[] = [
{
id: 'site-id-123',
name: 'site one',
totalDevicesCount: 0,
correctDevicesCount: 0,
Expand Down
1 change: 0 additions & 1 deletion udmif/web/src/app/sites/sites.gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const GET_SITES = gql`
query GetSites($searchOptions: SearchOptions) {
sites(searchOptions: $searchOptions) {
sites {
id
name
totalDevicesCount
correctDevicesCount
Expand Down
1 change: 0 additions & 1 deletion udmif/web/src/app/sites/sites.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('SitesService', () => {
sites: {
sites: [
{
id: '123',
name: 'site one',
totalDevicesCount: 0,
correctDevicesCount: 0,
Expand Down