chore(test): convert apps/stats test to TypeScript (#704)

This commit is contained in:
mackie 2018-10-25 12:13:09 -07:00 committed by Brandon Keepers
parent 85502cf3da
commit f82d647f51
2 changed files with 34 additions and 28 deletions

View File

@ -1,8 +1,8 @@
import { AnyResponse } from '@octokit/rest'
import { Request,Response } from 'express'
import { Request, Response } from 'express'
// Built-in app to expose stats about the deployment
module.exports = async (app: any): Promise<void> => {
export = async (app: any): Promise<void> => {
if (process.env.DISABLE_STATS) {
return
}

View File

@ -1,11 +1,13 @@
const request = require('supertest')
const express = require('express')
const nock = require('nock')
const helper = require('./helper')
const appFn = require('../../src/apps/stats')
import express from 'express'
import nock from 'nock'
import request from 'supertest'
import { Application } from '../../src'
import appFn = require('../../src/apps/stats')
import { createApp } from './helper'
describe('stats app', function () {
let app, server
describe('stats app', () => {
let app: Application
let server: express.Application
beforeEach(() => {
// Clean up env variable
@ -17,21 +19,23 @@ describe('stats app', function () {
describe('GET /probot/stats', () => {
beforeEach(async () => {
nock('https://api.github.com')
.defaultReplyHeaders({'Content-Type': 'application/json'})
.post('/app/installations/1/access_tokens').reply(200, {token: 'test'})
.get('/app/installations?per_page=100').reply(200, [{id: 1, account: {login: 'testing'}}])
.get('/installation/repositories?per_page=100').reply(200, {repositories: [
{private: true, stargazers_count: 1},
{private: false, stargazers_count: 2}
]})
.defaultReplyHeaders({ 'Content-Type': 'application/json' })
.post('/app/installations/1/access_tokens').reply(200, { token: 'test' })
.get('/app/installations?per_page=100').reply(200, [{ id: 1, account: { login: 'testing' } }])
.get('/installation/repositories?per_page=100').reply(200, {
repositories: [
{ private: true, stargazers_count: 1 },
{ private: false, stargazers_count: 2 }
]
})
app = helper.createApp(appFn)
app = createApp(appFn)
server.use(app.router)
})
it('returns installation count and popular accounts', () => {
return request(server).get('/probot/stats')
.expect(200, {'installations': 1, 'popular': [{login: 'testing', stars: 2}]})
.expect(200, { 'installations': 1, 'popular': [{ login: 'testing', stars: 2 }] })
})
})
@ -39,7 +43,7 @@ describe('stats app', function () {
beforeEach(async () => {
process.env.DISABLE_STATS = 'true'
app = helper.createApp(appFn)
app = createApp(appFn)
server.use(app.router)
})
@ -52,21 +56,23 @@ describe('stats app', function () {
beforeEach(async () => {
process.env.IGNORED_ACCOUNTS = 'hiimbex,spammyUser'
nock('https://api.github.com')
.defaultReplyHeaders({'Content-Type': 'application/json'})
.post('/app/installations/1/access_tokens').reply(200, {token: 'test'})
.get('/app/installations?per_page=100').reply(200, [{id: 1, account: {login: 'spammyUser'}}])
.get('/installation/repositories?per_page=100').reply(200, {repositories: [
{private: true, stargazers_count: 1},
{private: false, stargazers_count: 2}
]})
.defaultReplyHeaders({ 'Content-Type': 'application/json' })
.post('/app/installations/1/access_tokens').reply(200, { token: 'test' })
.get('/app/installations?per_page=100').reply(200, [{ id: 1, account: { login: 'spammyUser' } }])
.get('/installation/repositories?per_page=100').reply(200, {
repositories: [
{ private: true, stargazers_count: 1 },
{ private: false, stargazers_count: 2 }
]
})
app = helper.createApp(appFn)
app = createApp(appFn)
server.use(app.router)
})
it('returns installation count and popular accounts while exclusing spammy users', () => {
return request(server).get('/probot/stats')
.expect(200, {'installations': 1, 'popular': []})
.expect(200, { 'installations': 1, 'popular': [] })
})
afterEach(async () => {