Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
nock('https://api.github.com')
.post(/\/installations\/[\d\w-]+\/access_tokens/)
.reply(200, {
token: 'mocked-token',
expires_at: '9999-12-31T23:59:59Z'
})
.get('/repos/test-repo-owner/test-repo-name/contents/.github/jira.yml')
.reply(200, {
content: Buffer.from(`jira: ${process.env.ATLASSIAN_URL}`).toString('base64')
})
const configureRobot = require('../../lib/configure-robot')
global.app = configureRobot(new Application({
app: createGitHubApp({
id: 12257,
cert: findPrivateKey()
}),
cache: cacheManager.caching({
store: 'memory',
ttl: 60 * 60 // 1 hour
})
}))
})
const createTestApp = ({ toxicity }) => {
// PERSPECTIVE_API_KEY must be set
process.env.PERSPECTIVE_API_KEY = 'mock-key'
const app = new Application()
plugin(app)
const github = {
repos: {
getContent: expect.createSpy().andReturn(Promise.resolve({
data: {
content: Buffer.from(`
sentimentBotToxicityThreshold: 0.3
sentimentBotReplyComment: "That comment was toxic"`).toString('base64')
}
})),
get: expect.createSpy().andReturn(Promise.resolve({
data: {
code_of_conduct: Buffer.from(`
name: 'Contributor Covenenant'
url: https://github.com/hiimbex/testing-things/blob/master/CODE_OF_CONDUCT.md`).toString('base64')
beforeEach(() => {
app = new Application()
plugin(app)
github = new GitHubAPI()
app.auth = () => Promise.resolve(github)
})
exports.gimmeApp = () => {
let app, github
const logger = {
trace: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
fatal: jest.fn()
}
app = new Application({ logger })
app.load(plugin)
github = {
issues: {
create: jest.fn().mockName('issues.create'),
createLabel: jest.fn().mockName('issues.createLabel'),
update: jest.fn().mockName('issues.update'),
createComment: jest.fn().mockName('issues.createComment'),
updateComment: jest.fn().mockName('issues.updateComment'),
listComments: jest.fn(() => Promise.resolve({ data: [] })).mockName('issues.listComments')
},
search: {
issuesAndPullRequests: jest.fn(() => Promise.resolve({ data: { total_count: 0, items: [] } })).mockName('search.issuesAndPullRequests')
},
git: {
getCommit: jest.fn(() => Promise.resolve({ data: { parents: [1] } })).mockName('git.getCommit')
beforeEach(() => {
app = new Application();
plugin(app);
github = new GitHubAPI();
app.auth = () => Promise.resolve(github);
});
beforeEach(async() => {
githubNock = nock("https://api.github.com");
bot = new probot.Application({
id: "test",
cert: "test",
cache: {
wrap: () => Promise.resolve({ data: { token: "test" } })
},
app: () => "test"
});
const { paginate } = await bot.auth();
bot.auth = () => Object.assign(new GitHubApi(), { paginate });
nock.disableNetConnect();
autoCloser(bot);
});
function runBot({ issueTitle, labelNames, eventTypes }) {
issueWasCreated = false;
const bot = new probot.Application({
id: "test",
cert: "test",
cache: {
wrap: () => Promise.resolve({ data: { token: "test" } })
}
});
bot.auth = () => new GitHubApi();
recurringIssues(bot);
const ORGANIZATION_NAME = "test";
const TEAM_ID = 55;
nock("https://api.github.com")
.get(`/repos/${ORGANIZATION_NAME}/repo-test/issues/1/events?per_page=100`)
.reply(200, eventTypes.map(type => ({ event: type })));
beforeEach(async() => {
bot = new probot.Application({
id: "test",
cert: "test",
cache: {
wrap: () => Promise.resolve({ data: { token: "test" } })
},
app: () => "test"
});
const { paginate } = await bot.auth();
bot.auth = () => Object.assign(new GitHubApi(), { paginate });
nock.disableNetConnect();
nock("https://api.github.com")
.get("/app/installations")
export function createApplication (opts: {
logger: LoggerWithTarget,
appFn: ApplicationFunction,
github: GitHubAPI
}): Application {
const app = new Application()
app.log = opts.logger
app.auth = () => {
return Promise.resolve(opts.github)
}
app.load(opts.appFn)
return app
}
beforeAll(async() => {
bot = new Application({
id: "test",
cert: "test",
cache: {
wrap: () => Promise.resolve({ data: { token: "test" } })
},
app: () => "test"
});
const { paginate } = await bot.auth();
bot.auth = () => Object.assign(new GitHubApi(), { paginate });
releaseMonitor(bot);
});