How to use createInstallationToken method in Best

Best JavaScript code snippet using best

push.test.ts

Source: push.test.ts Github

copy

Full Screen

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 });...

Full Screen

Full Screen

managment.ts

Source: managment.ts Github

copy

Full Screen

...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,...

Full Screen

Full Screen

queries.test.ts

Source: queries.test.ts Github

copy

Full Screen

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 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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}

Full Screen

Using AI Code Generation

copy

Full Screen

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](

Full Screen

Using AI Code Generation

copy

Full Screen

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;

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

LambdaTest Receives Top Distinctions for Test Management Software from Leading Business Software Directory

LambdaTest has recently received two notable awards from the leading business software directory FinancesOnline after their experts were impressed with our test platform’s capabilities in accelerating one’s development process.

Some Common Layout Ideas For Web Pages

The layout of a web page is one of the most important features of a web page. It can affect the traffic inflow by a significant margin. At times, a designer may come up with numerous layout ideas and sometimes he/she may struggle the entire day to come up with one. Moreover, design becomes even more important when it comes to ensuring cross browser compatibility.

16 Best Chrome Extensions For Developers

Chrome is hands down the most used browsers by developers and users alike. It is the primary reason why there is such a solid chrome community and why there is a huge list of Chrome Extensions targeted at developers.

Why Your Startup Needs Test Management?

In a startup, the major strength of the people is that they are multitaskers. Be it anything, the founders and the core team wears multiple hats and takes complete responsibilities to get the ball rolling. From designing to deploying, from development to testing, everything takes place under the hawk eyes of founders and the core members.

Making A Mobile-Friendly Website: The Why And How?

We are in the era of the ‘Heads down’ generation. Ever wondered how much time you spend on your smartphone? Well, let us give you an estimate. With over 2.5 billion smartphone users, an average human spends approximately 2 Hours 51 minutes on their phone every day as per ComScore’s 2017 report. The number increases by an hour if we include the tab users as well!

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful