Skip to content
Open
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
57 changes: 38 additions & 19 deletions lansweeper/aws/integration-lambda/lansweeper_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
}
}
}`;
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions lansweeper/aws/integration-lambda/lansweeper_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
]
},
}
};
}
Expand Down Expand Up @@ -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"}]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,19 @@ 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 () => {
const response = await lansweeperClient.getAllInstallations(siteId1);
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",
},
);
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(() => ({
Expand Down Expand Up @@ -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) => {
Expand All @@ -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];
},
}));
Expand Down Expand Up @@ -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}`;
Expand All @@ -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];
},
}));
Expand Down Expand Up @@ -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}`;
Expand All @@ -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];
},
}));
Expand Down Expand Up @@ -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) => {
Expand All @@ -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];
},
}));
Expand Down Expand Up @@ -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) => {
Expand All @@ -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];
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
Loading