Skip to content

Commit

Permalink
feat: remove codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Nov 13, 2023
1 parent a506edf commit f4992fb
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 107 deletions.
375 changes: 308 additions & 67 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@
"loader": "esmock"
},
"dependencies": {
"@adobe/fetch": "^4.1.0",
"@adobe/fetch": "4.1.1",
"@adobe/helix-shared-secrets": "^2.1.2",
"@adobe/helix-shared-wrap": "2.0.0",
"@adobe/helix-status": "10.0.10",
"@adobe/helix-universal-logger": "3.0.11",
"@aws-sdk/client-dynamodb": "^3.427.0",
"@aws-sdk/client-s3": "^3.427.0",
"@aws-sdk/client-sqs": "^3.427.0",
"@aws-sdk/lib-dynamodb": "^3.427.0",
"axios": "1.5.1",
"@aws-sdk/client-s3": "3.427.0",
"@aws-sdk/client-sqs": "3.427.0",
"@aws-sdk/lib-dynamodb": "3.427.0",
"esm": "3.2.25"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions src/db-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* governing permissions and limitations under the License.
*/

'use strict';

import DB from './db.js';

export default function dynamoDBWrapper(func) {
Expand Down
28 changes: 26 additions & 2 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,26 @@ export default class DB {
* Saves an audit to the DynamoDB.
* @param {object} site - Site object containing details of the audited site.
* @param {object} audit - Audit object containing the type and result of the audit.
* @returns {Promise<void>} Resolves once audit is saved.
* @typedef {Object} audit
* @property {string} uuid - Audit unique identifier
* @property {string} siteId - Site unique identifier composed of domain and path.
* @property {string} auditDate - Date when audit was run.
* @property {string} type - Type of the run audit (default psi)
* @property {boolean} isLive - Indicates if the site is live at the time of the audit
* @property {string} git_hashes - Git commit hashes since the last audit was run.
* @property {string} tag_manager - Tag manager used for the site and the version.
* @property {string} error - The error if auditing returned an error.
* @property {Object[]} auditResults - The minified audit results from the psi checks
* @param {string} auditResults[].strategy - The psi audit strategy can be desktop or mobile.
* @param {object} auditResults[].scores - The minified results of the psi audit for the strategy.
* @param {object} auditResults[].score.performance - The performance score of psi check for
* the site strategy.
* @param {object} auditResults[].scores.seo - The seo score of psi check for the site strategy.
* @param {object} auditResults[].scores.best-practices - The best-practices score of psi check
* for the site strategy.
* @param {object} auditResults[].scores.accessibility - The accessibility score of psi check for
* the site strategy.
* @returns {Promise<object>} Resolves the new saved audit.
*/
async saveAuditIndex(site, audit) {
const now = new Date().toISOString();
Expand Down Expand Up @@ -83,7 +102,7 @@ export default class DB {
};
await this.saveRecord(newAudit, TABLE_AUDITS);
this.log.info(`Saving successful audit for domain ${site.domain} saved successfully`);
return Promise.resolve(newAudit);
return newAudit;
}

/**
Expand Down Expand Up @@ -134,4 +153,9 @@ export default class DB {
throw error;
}
}

destroy() {
this.docClient.destroy();
this.client.destroy();
}
}
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ async function run(request, context) {
});
}
message = JSON.parse(message);
const psiClient = PSIClient({
apiKey: context.env.PAGESPEED_API_KEY,
baseUrl: context.env.PAGESPEED_API_BASE_URL,
});

if (!message.domain) {
return new Response('', {
status: 400,
Expand All @@ -57,6 +52,11 @@ async function run(request, context) {
});
}

const psiClient = PSIClient({
apiKey: context.env.PAGESPEED_API_KEY,
baseUrl: context.env.PAGESPEED_API_BASE_URL,
});

const site = {
domain: message.domain,
path: message.path,
Expand All @@ -68,6 +68,8 @@ async function run(request, context) {
} catch (e) {
await db.saveAuditError(site, e);
}
db.destroy();
queue.destroy();
return new Response('SUCCESS');
}

Expand Down
5 changes: 3 additions & 2 deletions src/psi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import axios from 'axios';
import { fetch } from '@adobe/fetch';

function PSIClient(config) {
const AUDIT_TYPE = 'PSI';
Expand Down Expand Up @@ -138,7 +138,8 @@ function PSIClient(config) {
// eslint-disable-next-line no-useless-catch
try {
const apiURL = getPSIApiUrl(domain, strategy);
const { data: lhs } = await axios.get(apiURL);
const response = await fetch(apiURL);
const { data: lhs } = await response.json();

const { lighthouseResult } = processAuditData(lhs);

Expand Down
4 changes: 4 additions & 0 deletions src/sqs-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ export default class SQSQueue {
throw err;
}
}

destroy() {
this.sqsClient.destroy();
}
}
5 changes: 0 additions & 5 deletions test/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

/* eslint-env mocha */

import nock from 'nock';
import assert from 'assert';
import esmock from 'esmock';
import DB from '../src/db.js';
Expand Down Expand Up @@ -40,10 +39,6 @@ describe('DB Tests', () => {
};
});

afterEach(() => {
nock.cleanAll();
});

it('should initialize with provided context', () => {
const db = new DB(mockContext);
assert.strictEqual(db.log, mockContext.log);
Expand Down
5 changes: 0 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/* eslint-env mocha */

import assert from 'assert';
import nock from 'nock';
import { main } from '../src/index.js';

describe('Index Tests', () => {
Expand All @@ -33,10 +32,6 @@ describe('Index Tests', () => {
};
});

afterEach(() => {
nock.cleanAll();
});

it('index function returns an error if not triggered by an event', async () => {
const response = await main({}, mockContext);
assert.strictEqual(response.headers.get('x-error'), 'Action was not triggered by an event');
Expand Down
12 changes: 3 additions & 9 deletions test/psi-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ describe('PSIClient', () => {
});

describe('runAudit', () => {
beforeEach(() => {

});

afterEach(() => {
nock.cleanAll();
});
Expand Down Expand Up @@ -172,24 +168,22 @@ describe('PSIClient', () => {
.get('/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2Fexample.com&key=test-api-key&strategy=mobile&category=performance&category=accessibility&category=best-practices&category=seo')
.reply(200, { data: {} });
const data = await client.performPSICheck('example.com');
assert.deepEqual(data, expectedResult); // Assuming axios mock returns empty object as data
assert.deepEqual(data, expectedResult);
});

// Input edge cases for performPSICheck
it('should handle empty domain input gracefully', async () => {
nock('https://www.googleapis.com')
.get('/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2F&key=test-api-key&strategy=mobile&category=performance&category=accessibility&category=best-practices&category=seo')
.reply(200, { data: {} });
const data = await client.performPSICheck('');
assert.deepEqual(data, expectedResult); // Assuming axios mock returns empty object for any input
assert.deepEqual(data, expectedResult);
});

it('should handle domain with special characters', async () => {
nock('https://www.googleapis.com')
.get('/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2Fexample.com/some%20path&key=test-api-key&strategy=mobile&category=performance&category=accessibility&category=best-practices&category=seo')
.reply(200, { data: {} });
const data = await client.performPSICheck('example.com/some path');
assert.deepEqual(data, expectedResult); // Assuming axios mock returns empty object for any input
assert.deepEqual(data, expectedResult);
});
});

Expand Down
5 changes: 0 additions & 5 deletions test/sqs-queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/* eslint-env mocha */

import assert from 'assert';
import nock from 'nock';
import esmock from 'esmock';
import SqsClientMock from './sqs-client-mock.js';
import SQSQueue from '../src/sqs-queue.js';
Expand Down Expand Up @@ -44,10 +43,6 @@ describe('SQSQueue Tests', () => {
};
});

afterEach(() => {
nock.cleanAll();
});

it('should initialize with provided context', () => {
const queue = new SQSQueue(mockContext);
assert.strictEqual(queue.queueUrl, mockContext.attributes.queueUrl);
Expand Down

0 comments on commit f4992fb

Please sign in to comment.