Best JavaScript code snippet using best
push.test.ts
Source: push.test.ts
1import mockingoose from 'mockingoose';2import { Context } from 'probot';3import handlePush from '../../src/handlers/push';4import runsModel from '../../src/models/runs.model';5describe('push handler', () => {6 let event: any;7 let context: Context;8 let config: any;9 let token: string;10 let id: string;11 let callbackUrl: string;12 beforeEach(async () => {13 id = [ ...Array(24) ].map(() => Math.floor(Math.random() * 16).toString(16)).join('');14 callbackUrl = 'https://geocities.com';15 token = 'secret42';16 event = {17 id: '123',18 name: 'push',19 payload: {20 ref: "refs/heads/main",21 before: "bc5b6d4f4a5b2eb3d89f52d46d75f2129c63b074",22 after: "89c9e6dc89fce3971570dba9b07052973bff7e13",23 repository: {24 id: 33241,25 name: 'rudolph',26 full_name: 'santa/rudolph',27 owner: {28 login: 'santa'29 }30 },31 installation: {32 id: 4233 }34 }35 };36 context = new Context(event, {} as any, {} as any);37 context.octokit.apps = {38 getWebhookConfigForApp: jest.fn().mockImplementation(async () => ({39 data: { url: callbackUrl }40 })),41 createInstallationAccessToken: jest.fn().mockImplementation(async () => ({ data: { token } }))42 } as any;43 context.octokit.repos = {44 createDispatchEvent: jest.fn().mockImplementation(async () => { })45 } as any;46 config = {47 workflows_repository: '.github',48 include_workflows_repository: false,49 exclude: {50 repositories: []51 }52 };53 context.octokit.config = {54 get: jest.fn().mockImplementation(async () => ({ config }))55 };56 mockingoose(runsModel).toReturn({ _id: id }, 'save');57 });58 describe('include/exclude logic', () => {59 describe('current repository is workflow repository', () => {60 beforeEach(() => {61 event.payload.repository.name = '.github';62 });63 test('should not call createInstallationToken', async () => {64 await handlePush(context);65 expect(context.octokit.apps.createInstallationAccessToken).not.toBeCalled();66 });67 });68 describe('current repository is workflow repository but workflow repository should be included', () => {69 beforeEach(() => {70 event.payload.repository.name = '.github';71 config.include_workflows_repository = true;72 });73 test('should not call createInstallationToken', async () => {74 await handlePush(context);75 expect(context.octokit.apps.createInstallationAccessToken).toBeCalled();76 });77 });78 describe('current repository is not workflow repository', () => {79 beforeEach(() => {80 event.payload.repository.name = 'foo-github';81 });82 test('should call createInstallationToken', async () => {83 await handlePush(context);84 expect(context.octokit.apps.createInstallationAccessToken).toBeCalled();85 });86 });87 });88 describe('createInstallationAccessToken logic', () => {89 test('should createInstallationAccessToken that is scoped to push repository', async () => {90 await handlePush(context);91 expect(context.octokit.apps.createInstallationAccessToken).toBeCalledWith({92 installation_id: event.payload.installation.id,93 repository_ids: [ event.payload.repository.id ]94 });95 });96 });97 describe('createDispatchEvent logic', () => {98 test('should call octokit createDispatchEvent correct data', async () => {99 await handlePush(context);100 expect(context.octokit.repos.createDispatchEvent).toBeCalledWith({101 owner: context.payload.repository.owner.login,102 repo: ".github",103 event_type: "org-workflow-bot",104 client_payload: {105 sha: context.payload.after,106 id: id,107 token: token,108 callback_url: `${callbackUrl}/org-workflows/register`,109 repository: {110 full_name: context.payload.repository.full_name,111 name: context.payload.repository.name,112 owner: context.payload.repository.owner.login,113 },114 event: event.payload115 }116 });117 });118 });...
managment.ts
Source: managment.ts
...20router.use(authValidator)21router.post('/refresh-install-token/', async (req, res) => {22 const installId = req.body.installationId23 const owner = await GithubOwner.findOneOrFail({ where: { installationId: installId } })24 await createInstallationToken(installId)25 const acessToken = await createInstallationToken(owner.installationId)26 owner.oldAcessTokens.push(owner.githubAccessToken);27 owner.githubAccessToken = acessToken.token;28 await owner.save()29 res.sendStatus(200)30})31router.post('/reload-owner-repos/', async (req, res) => {32 const installId = req.body.installationId33 const owner = await GithubOwner.findOneOrFail({ where: { installationId: installId } })34 let repos = await getInstallationRepos(owner.githubAccessToken)35 for (let repo of repos) {36 await Repository.updateOrCreate({ githubId: repo.id }, {37 githubId: repo.id,38 name: repo.name,39 rawData: repo as any,...
queries.test.ts
Source: queries.test.ts
1import { fetchInstallationIds, fetchTokenForInstallation } from './queries';2import * as Octokit from '@octokit/rest';3// Cleanly double cast an octokitMock object to Octokit to appease TypeScript4function mockOctokit(octokitMock: any): Octokit {5 return octokitMock as Octokit;6}7describe('github helpers', () => {8 beforeEach(() => jest.resetAllMocks());9 afterEach(() => jest.resetAllMocks());10 describe(fetchInstallationIds, () => {11 test('should return installation IDs', async () => {12 const apiResult = require('./__mocks__/octokit.apps.getInstallations.valid.json');13 const octokit = mockOctokit({14 apps: {15 getInstallations: jest.fn().mockResolvedValue({ data: apiResult }),16 },17 });18 await expect(fetchInstallationIds(octokit)).resolves.toEqual([1]);19 });20 });21 describe(fetchTokenForInstallation, () => {22 test('should return token', async () => {23 const apiResult = require('./__mocks__/octokit.apps.createInstallationToken.valid.json');24 const octokit = mockOctokit({25 apps: {26 createInstallationToken: jest.fn().mockResolvedValue({ data: apiResult }),27 },28 });29 await expect(fetchTokenForInstallation('1', octokit)).resolves.toEqual(apiResult.token);30 });31 });...
Using AI Code Generation
1module.exports = app => {2 app.on('installation.created', async context => {3 const token = await context.github.apps.createInstallationToken({ installation_id: installation.id })4 const newGithub = new GitHub({5 })6 const { data: user } = await newGithub.users.getForUser({7 })8 const { data: issue } = await newGithub.issues.create({9 title: `Welcome @${user.login}!`,10 body: `Thanks for installing this app, @${user.login}. I will be in touch!`11 })12 await newGithub.issues.createComment({13 body: `@${user.login} is awesome!`14 })15 })16}
Using AI Code Generation
1const BestMatch = require('best-match');2const bestMatch = new BestMatch();3 { name: 'John', age: 20 },4 { name: 'Peter', age: 25 },5 { name: 'Mary', age: 30 }6];7MIT © [Nikhil](
Using AI Code Generation
1const BestFit = require('bestfit');2const fs = require('fs');3const path = require('path');4const rimraf = require('rimraf');5const config = require('../config');6const { log, logError } = require('../utils/log');7const { getInstallationToken } = require('../utils/gh');8const {9} = config;10const bestfit = new BestFit({11});12let installationId;13let token;14let repositoryId;15let issueId;16let branchId;17let fileId;18let pullRequestId;19let releaseId;20let releaseAssetId;
Check out the latest blogs from LambdaTest on this topic:
Ever wondered how you went to YouTube to watch just a 5 minutes video but ended up there for 3 hours? Or saw an advertisement on some page of exactly the same thing that you have been planning to buy for last 15 days and ended up finally buying it! Isn’t it great how your computer knows what you have been desiring? Well, it’s not your computer but the bots, the algorithmic bots that have been watching you all the time. Even now! Yes, that’s absolutely true. So the question comes, how these bots are made, and how software testing concepts come into play here.
Adoption of DevOps and Agile has been one of the biggest trends to be seen in 2017 in the testing domain. A rising trend in the domain of
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Cross Browser Testing Tutorial.
Gone are the olden times when the more you scaled your application, the further your tests were complicated. At present, every QA team aims to cover a maximum number of functional tests in the least amount of time, thanks to parallel testing. Using virtualization, parallel testing allows you to perform multiple tests at the same time. As simple as it sounds, it can exponentially minimize your testing time, resulting in a fastened release process. Let’s delve in to see some amazing improvements you can bring about in your work by introducing parallel testing into it.
No matter how big or small your webapp is, you cannot disrespect browser diversity. No matter what is your target audience, you should always aim to develop a website that is cross browser compatible. Between Safari, Chrome, Opera, Firefox and Internet Explorer, one cannot certainly be sure that the developed webpage will run properly in the other’s system just because it did in your local machine. The problem is more magnified if you are developing a JavaScript webapp.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!