'use strict' ; import { Agent , Application } from 'egg' ; import { prepareTestApplication , testClear , waitFor } from '../../Util' ; import { initWebhooks , sendToWebhooks } from './gitee-test-util' ; import { readFileSync } from 'fs' ; import { join } from 'path' ; import { convertIssueNumber2Number , convertIssueNumber2String } from '../../../app/plugin/gitee/util' ; import assert from 'power-assert' ; describe ( 'GiteeApp' , ( ) => { let app ; let agent ; let testResult ; before ( async ( ) => { ( { app , agent } = await prepareTestApplication ( ) ) ; testResult = await initWebhooks ( app ) ; } ) ; after ( ( ) => { testClear ( app , agent ) ; } ) ; afterEach ( ( ) => { testResult . length = 0 ; } ) ; it ( 'issue opened lead to difficulty/5 label added' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/issue-hook-open.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ [ 'addLabels' , 734957508981 , [ 'kind/bug' , 'area/document' ] ] , [ 'assign' , 734957508981 , 'GoodMeowing' ] , ] ) ; } ) ; it ( 'push hook' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/push-hook.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ ] ) ; } ) ; it ( 'merge request opened' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/merge-request-hook-open.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ [ 'addLabels' , 1 , [ 'kind/bug' ] ] ] ) ; } ) ; it ( 'merge request closed' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/merge-request-hook-close.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ ] ) ; } ) ; it ( 'issue comment opened' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/note-hook-comment-issue.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ [ 'assign' , 734957508981 , 'goodmeowing' ] ] ) ; } ) ; it ( 'issue comment edited' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/note-hook-edited-issue.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ [ 'assign' , 734957487868 , 'goodmeowing' ] ] ) ; } ) ; it ( 'issue comment closed' , async ( ) => { const noteHookPath = join ( __dirname , './data/webhook/note-hook-deleted-issue.json' ) ; const request = JSON . parse ( readFileSync ( noteHookPath ) . toString ( ) ) ; await sendToWebhooks ( app , request . headers , request . payload ) ; await waitFor ( 30 ) ; assert . deepStrictEqual ( testResult , [ ] ) ; } ) ; it ( 'convert string and number into each other' , async ( ) => { assert . deepStrictEqual ( convertIssueNumber2Number ( 'I192YQ' ) , 734957508981 ) ; assert . deepStrictEqual ( convertIssueNumber2String ( 734957508981 ) , 'I192YQ' ) ; } ) ; } ) ;