diff --git a/lansweeper/aws/integration-lambda/lansweeper_client.js b/lansweeper/aws/integration-lambda/lansweeper_client.js index 972652b..ce8e06d 100644 --- a/lansweeper/aws/integration-lambda/lansweeper_client.js +++ b/lansweeper/aws/integration-lambda/lansweeper_client.js @@ -64,7 +64,7 @@ class LansweeperClient { const installationsPerSite = await this.getInstallationsPerSite(); return [...installationsPerSite.values()] .reduce((memo, i) => memo.concat(i)) - .map(i => i.name); + .map(i => i.displayName); } async getInstallationsPerSite() { @@ -90,24 +90,43 @@ class LansweeperClient { } // the 'id' returned for each installation can be used to filter assets based on their 'installationId' field. - const query = `query getInstallations($siteId: ID!) { + const query = `query listSources($siteId: ID!) { site(id: $siteId) { - allInstallations { - id - siteId - name - fqdn - description - unlinkedOn - unlinkedBy - linkStatus - installationDate - type - totalAssets - syncServerStatus - lastAvailable - version - syncServer + sources( + pagination: { limit: 100, page: FIRST } + filters: { + conjunction: AND + groups: [ + { + conditions: [ + { operator: EXISTS, path: "id", value: "true" } + ] + conjunction: AND + } + ] + } + ) { + total + pagination { + limit + current + next + page + } + items { + id + type + state { + value + unlinkedOnDate + deletedOnDate + firstSyncCompletedOn + } + siteId + createdAt + externalId + displayName + } } } }`; @@ -117,7 +136,7 @@ class LansweeperClient { {siteId: siteId}); let allForSite = result; if (!result.error) { - allForSite = result.site.allInstallations; + allForSite = result.site.sources.items; } this.installationsBySiteId.set(siteId, allForSite); return allForSite; diff --git a/lansweeper/aws/integration-lambda/lansweeper_integration.js b/lansweeper/aws/integration-lambda/lansweeper_integration.js index 86410bf..457c22d 100644 --- a/lansweeper/aws/integration-lambda/lansweeper_integration.js +++ b/lansweeper/aws/integration-lambda/lansweeper_integration.js @@ -63,12 +63,12 @@ class LansweeperIntegration { if (installations.error) { siteError = installations.error; } else { - const selectedInstallations = installations.filter(i => installationFilter(i.name)); + const selectedInstallations = installations.filter(i => installationFilter(i.displayName)); if (selectedInstallations.length === 0) { result.info[siteName] = 'No installations in this site matched selection'; } else { if (selectedInstallations.length > 1) { - console.log('Will process the following installations: %j', selectedInstallations.map(i => i.name)); + console.log('Will process the following installations: %j', selectedInstallations.map(i => i.displayName)); } const resultDownloadFunctions = await this.enqueueMutationsForInstallations(selectedInstallations, @@ -133,18 +133,18 @@ class LansweeperIntegration { async mergeInstallationResult(result, siteName, installation, installationResult) { result.uploadCounts[siteName] = result.uploadCounts[siteName] || {}; - result.uploadCounts[siteName][installation.name] = installationResult.uploadCount ?? 0; + result.uploadCounts[siteName][installation.displayName] = installationResult.uploadCount ?? 0; if (installationResult.errors) { result.errorCounts[siteName] = result.errorCounts[siteName] || {}; - result.errorCounts[siteName][installation.name] = installationResult.errors.length; + result.errorCounts[siteName][installation.displayName] = installationResult.errors.length; result.errors[siteName] = result.errors[siteName] || {}; - result.errors[siteName][installation.name] = installationResult.errors; + result.errors[siteName][installation.displayName] = installationResult.errors; } } async enqueueMutationsForInstallation(siteId, networkedAssetsOnly, generateLabels, installation, installationNames, assetTypes) { const siteName = await this.lansweeperClient.getSiteName(siteId); - const installationName = installation.name; + const installationName = installation.displayName; console.log(`processing site ${siteName}, installation ${installationName}. NetworkedAssetsOnly: ${networkedAssetsOnly}.${generateLabels ? ' Using asset name as label.' : ''}`); const sendResults = await this.startInstallationSync(siteId, networkedAssetsOnly, generateLabels, installation, installationName, installationNames, assetTypes); console.log(`Uploaded all assets for site ${siteName}, installation ${installationName}.`); diff --git a/lansweeper/aws/integration-lambda/tests/lansweeper_client.test.js b/lansweeper/aws/integration-lambda/tests/lansweeper_client.test.js index 175a37d..982622d 100644 --- a/lansweeper/aws/integration-lambda/tests/lansweeper_client.test.js +++ b/lansweeper/aws/integration-lambda/tests/lansweeper_client.test.js @@ -13,16 +13,18 @@ describe('retrieving installations with error for one site', () => { getGraphQLQuery: async (descr, query, vars) => { if (query.includes('authorizedSites')) { return {authorizedSites: {sites: [{id: 'a', name: 'site A'}, {id: 'b', name: 'site B'}]}}; - } else if (query.includes('allInstallations')) { + } else if (query.includes('listSources')) { if (vars.siteId === 'a') { return {error: `Unable to query ${descr}: [{message: 'You are not authorized'}]`}; } else { return { site: { - allInstallations: [ - {id: 'a', name: `install A for ${vars.siteId}`, siteId: vars.siteId}, - {id: 'b', name: `install B for ${vars.siteId}`, siteId: vars.siteId}, - ] + sources: { + items: [ + {id: 'a', displayName: `install A for ${vars.siteId}`, siteId: vars.siteId}, + {id: 'b', displayName: `install B for ${vars.siteId}`, siteId: vars.siteId}, + ] + }, } }; } @@ -52,7 +54,7 @@ describe('retrieving installations with error for one site', () => { const client = createClient(); const result = await client.getAllInstallations('b'); - expect(result).toEqual([{id: "a", name: "install A for b", siteId: "b"}, {id: "b", name: "install B for b", siteId: "b"}]); + expect(result).toEqual([{id: "a", displayName: "install A for b", siteId: "b"}, {id: "b", displayName: "install B for b", siteId: "b"}]); }); }); diff --git a/lansweeper/aws/integration-lambda/tests/lansweeper_client_int.test.js b/lansweeper/aws/integration-lambda/tests/lansweeper_client_int.test.js index 77a5ebc..585bf52 100644 --- a/lansweeper/aws/integration-lambda/tests/lansweeper_client_int.test.js +++ b/lansweeper/aws/integration-lambda/tests/lansweeper_client_int.test.js @@ -145,7 +145,7 @@ describe.skip('integration tests', () => { it('can get installation names for all sites', async () => { const names = await lansweeperClient.getAllInstallationNames(); - expect(names).toEqual(['Tampa JLerch', 'Widget Belgian HQ']); + expect(names).toEqual(['JL Master', 'Widget Belgian HQ', 'Tampa JLerch']); }); it('can get all installations', async () => { @@ -153,17 +153,11 @@ describe.skip('integration tests', () => { console.log('%j', response); expect(response.length).toEqual(2); - expect(response.find(i => i.siteId === siteId1 && i.syncServerStatus === 'Down')).toMatchObject( + expect(response.find(i => i.siteId === siteId1 && i.displayName === 'Tampa JLerch')).toMatchObject( { - "description": "US Based", - "fqdn": "", "id": installId, - "installationDate": "2022-09-21T15:32:13.099Z", - "linkStatus": "Linked", - "name": "Tampa JLerch", + "displayName": "Tampa JLerch", "siteId": siteId1, - "syncServer": "jl-master", - "syncServerStatus": "Down", "type": "IT", }, ); @@ -186,7 +180,7 @@ describe.skip('integration tests', () => { console.log('assets:\n%j', results); const h = new LansweeperHelper(); const un = h.extractUserNames(results); - expect(results.length).toEqual(55); + expect(results.length).toEqual(4); }); it('can get assets paged for single installation', async () => { @@ -201,7 +195,7 @@ describe.skip('integration tests', () => { const h = new LansweeperHelper(); const un = h.extractUserNames(results); - expect(results.length).toEqual(49); + expect(results.length).toEqual(4); }); it('can get assets paged for single installation and limited asset types', async () => { diff --git a/lansweeper/aws/integration-lambda/tests/lansweeper_integration.test.js b/lansweeper/aws/integration-lambda/tests/lansweeper_integration.test.js index 7d950bb..93ca2f9 100644 --- a/lansweeper/aws/integration-lambda/tests/lansweeper_integration.test.js +++ b/lansweeper/aws/integration-lambda/tests/lansweeper_integration.test.js @@ -33,9 +33,9 @@ describe('downloadAndReduceSiteResults', () => { const result = {uploadCounts: {}, errorCounts: {}, info: {}, errors: {}}; const resultDownloadFunctions = new Map(); - resultDownloadFunctions.set({id: '0', name: 'installation1'}, + resultDownloadFunctions.set({id: '0', displayName: 'installation1'}, async () => ({uploadCount: 2})); - resultDownloadFunctions.set({id: '1', name: 'installation2'}, + resultDownloadFunctions.set({id: '1', displayName: 'installation2'}, async () => ({uploadCount: 6})); await integration.downloadAndReduceSiteResults(resultDownloadFunctions, result, siteName); @@ -57,9 +57,9 @@ describe('downloadAndReduceSiteResults', () => { const result = {uploadCounts: {}, errorCounts: {}, info: {}, errors: {}}; const resultDownloadFunctions = new Map(); - resultDownloadFunctions.set({id: '0', name: 'installation1'}, + resultDownloadFunctions.set({id: '0', displayName: 'installation1'}, async () => ({errors: ['a', 'c']})); - resultDownloadFunctions.set({id: '1', name: 'installation2'}, + resultDownloadFunctions.set({id: '1', displayName: 'installation2'}, async () => ({errors: ['b']})); await integration.downloadAndReduceSiteResults(resultDownloadFunctions, result, siteName); @@ -91,9 +91,9 @@ describe('downloadAndReduceSiteResults', () => { const result = {uploadCounts: {}, errorCounts: {}, info: {}, errors: {}}; const resultDownloadFunctions = new Map(); - resultDownloadFunctions.set({id: '0', name: 'installation1'}, + resultDownloadFunctions.set({id: '0', displayName: 'installation1'}, async () => ({errors: ['a', 'c']})); - resultDownloadFunctions.set({id: '1', name: 'installation2'}, + resultDownloadFunctions.set({id: '1', displayName: 'installation2'}, async () => ({uploadCount: 2})); await integration.downloadAndReduceSiteResults(resultDownloadFunctions, result, siteName); @@ -130,7 +130,7 @@ describe('processSite', () => { } }`; - const installations = [{id: 1, name: 'a'}, {id: 3, name: 'b'}]; + const installations = [{id: 1, displayName: 'a'}, {id: 3, displayName: 'b'}]; beforeEach(() => { TimeHelper.mockImplementation(() => ({ @@ -537,7 +537,7 @@ describe('processSite', () => { if (siteId === 'a') { return {error: 'No installations for site a'}; } else { - return installations.map(i => ({...i, name: `${i.name} for ${siteId}`})); + return installations.map(i => ({...i, displayName: `${i.displayName} for ${siteId}`})); } }, getSiteName: async (id) => { @@ -547,7 +547,7 @@ describe('processSite', () => { expect(id).toBe('b'); const installation = installations.find(i => i.id === installationKey); expect(installation).not.toBeUndefined(); - const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.name, installations.map(i => i.name)); + const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.displayName, installations.map(i => i.displayName)); return [...result1]; }, })); @@ -650,7 +650,7 @@ describe('processSite', () => { }, getAllInstallationNames: async () => allInstallationNames, getAllInstallations: async (siteId) => { - return installations.map(i => ({...i, name: `${i.name} for ${siteId}`})); + return installations.map(i => ({...i, displayName: `${i.displayName} for ${siteId}`})); }, getSiteName: async (id) => { return `site ${id}`; @@ -659,7 +659,7 @@ describe('processSite', () => { expect(id).toBe('b'); const installation = installations.find(i => i.id === installationKey); expect(installation).not.toBeUndefined(); - const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.name, installations.map(i => i.name)); + const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.displayName, installations.map(i => i.displayName)); return [...result1]; }, })); @@ -763,7 +763,7 @@ describe('processSite', () => { getAllInstallationNames: async () => allInstallationNames, getAllInstallations: async (siteId) => { expect(siteId).not.toEqual('a'); - return installations.map(i => ({...i, name: `${i.name} for ${siteId}`})); + return installations.map(i => ({...i, displayName: `${i.displayName} for ${siteId}`})); }, getSiteName: async (id) => { return `site ${id}`; @@ -772,7 +772,7 @@ describe('processSite', () => { expect(assetTypes).toEqual(['ipad', 'linux']); const installation = installations.find(i => i.id === installationKey); expect(installation).not.toBeUndefined(); - const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.name, installations.map(i => i.name)); + const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.displayName, installations.map(i => i.displayName)); return [...result1]; }, })); @@ -916,7 +916,7 @@ describe('processSite', () => { if (siteId === 'a') { return {error: 'No installations for site a'}; } else { - return installations.map(i => ({...i, name: `${i.name} for ${siteId}`})); + return installations.map(i => ({...i, displayName: `${i.displayName} for ${siteId}`})); } }, getSiteName: async (id) => { @@ -926,7 +926,7 @@ describe('processSite', () => { expect(id).toBe('b'); const installation = installations.find(i => i.id === installationKey); expect(installation).not.toBeUndefined(); - const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.name, installations.map(i => i.name)); + const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.displayName, installations.map(i => i.displayName)); return [...result1]; }, })); @@ -1043,7 +1043,7 @@ describe('processSite', () => { if (siteId === 'a') { return {error: 'No installations for site a'}; } else { - return installations.map(i => ({...i, name: `${i.name} for ${siteId}`})); + return installations.map(i => ({...i, displayName: `${i.displayName} for ${siteId}`})); } }, getSiteName: async (id) => { @@ -1053,7 +1053,7 @@ describe('processSite', () => { expect(id).toBe('b'); const installation = installations.find(i => i.id === installationKey); expect(installation).not.toBeUndefined(); - const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.name, installations.map(i => i.name)); + const result1 = await handler(assetArray, networkedAssetsOnly, false, installation.displayName, installations.map(i => i.displayName)); return [...result1]; }, })); diff --git a/note-dispatcher/aws/integration-lambda/tests/fun_translations_helper.test.js b/note-dispatcher/aws/integration-lambda/tests/fun_translations_helper.test.js index c946194..65ed82a 100644 --- a/note-dispatcher/aws/integration-lambda/tests/fun_translations_helper.test.js +++ b/note-dispatcher/aws/integration-lambda/tests/fun_translations_helper.test.js @@ -2,7 +2,7 @@ const FunTranslationsHelper = require('../fun_translations_helper') -it('can translate', async () => { +it.skip('can translate', async () => { const helper = new FunTranslationsHelper(); const translation = 'pirate'; @@ -15,13 +15,13 @@ it('can translate', async () => { expect(response.translated).not.toBeNull(); }); -it('supports multiple translations', async () => { +it.skip('supports multiple translations', async () => { const helper = new FunTranslationsHelper(); expect(helper.translations.length).toBeGreaterThan(0); expect(helper.translations).toBe(FunTranslationsHelper.TRANSLATIONS); }); -it('can generate random translation', async () => { +it.skip('can generate random translation', async () => { const helper = new FunTranslationsHelper(); const text = 'Just do it';