'use strict' ; import * as SlackHelper from '../../../../../app/basic/helper/weekly-report/slack-helper' ; import assert from 'power-assert' ; import { SectionBlock } from '@slack/types' ; describe ( 'Utils' , ( ) => { describe ( 'generateSlackWeeklyReport' , ( ) => { it ( 'pass null value' , async ( ) => { const res = SlackHelper . generateSlackWeeklyReport ( null as any , null as any , null as any , null as any , null as any , null as any , null as any , null as any ) ; assert ( res . blocks !== undefined ) ; if ( res . blocks ) { assert ( res . blocks . length === 18 ) ; } } ) ; it ( 'pass undefined value' , async ( ) => { const res = SlackHelper . generateSlackWeeklyReport ( undefined as any , undefined as any , undefined as any , undefined as any , undefined as any , undefined as any , undefined as any , undefined as any ) ; assert ( res . blocks !== undefined ) ; if ( res . blocks ) { assert ( res . blocks . length === 18 ) ; } } ) ; it ( 'pass currect type' , async ( ) => { const basicDataTable = new Map < string , string > ( ) ; const issueAndPRsTable = new Map < string , string > ( ) ; const prsTable = new Map < string , string > ( ) ; const codeReviewTable = new Map < string , string > ( ) ; const contributors = [ ] ; const res = SlackHelper . generateSlackWeeklyReport ( '' , basicDataTable , issueAndPRsTable , prsTable , 10 , codeReviewTable , contributors , '' ) ; assert ( res . blocks !== undefined ) ; if ( res . blocks ) { assert ( res . blocks . length === 18 ) ; } } ) ; it ( 'pass currect value' , async ( ) => { const basicDataTable = new Map < string , string > ( ) ; const issueAndPRsTable = new Map < string , string > ( ) ; const prsTable = new Map < string , string > ( ) ; const codeReviewTable = new Map < string , string > ( ) ; const contributors = [ ] ; basicDataTable . set ( 'a' , 'a' ) ; issueAndPRsTable . set ( 'a' , 'a' ) ; prsTable . set ( 'a' , 'a' ) ; codeReviewTable . set ( 'a' , 'a' ) ; contributors . push ( 'a' ) ; const res = SlackHelper . generateSlackWeeklyReport ( '' , basicDataTable , issueAndPRsTable , prsTable , 10 , codeReviewTable , contributors , '' ) ; assert ( res . blocks !== undefined ) ; if ( res . blocks ) { assert ( res . blocks . length === 24 ) ; } } ) ; it ( 'pass currect value, count value number' , async ( ) => { const basicDataTable = new Map < string , string > ( ) ; const issueAndPRsTable = new Map < string , string > ( ) ; const prsTable = new Map < string , string > ( ) ; const codeReviewTable = new Map < string , string > ( ) ; const contributors = [ ] ; const num = 10 ; for ( let i = 0 ; i < num ; i ++ ) { basicDataTable . set ( i . toString ( ) , i . toString ( ) ) ; issueAndPRsTable . set ( i . toString ( ) , i . toString ( ) ) ; prsTable . set ( i . toString ( ) , i . toString ( ) ) ; codeReviewTable . set ( i . toString ( ) , i . toString ( ) ) ; contributors . push ( i . toString ( ) ) ; } const res = SlackHelper . generateSlackWeeklyReport ( '' , basicDataTable , issueAndPRsTable , prsTable , 10 , codeReviewTable , contributors , '' ) ; assert ( res . blocks !== undefined ) ; if ( res . blocks ) { const t1 = ( res . blocks [ 6 ] as SectionBlock ) ; if ( t1 . fields ) { assert ( t1 . fields . length === num * 2 ) ; } else { assert ( false ) ; } const t2 = ( res . blocks [ 10 ] as SectionBlock ) ; if ( t2 . fields ) { assert ( t2 . fields . length === num * 2 ) ; } else { assert ( false ) ; } const t3 = ( res . blocks [ 14 ] as SectionBlock ) ; if ( t3 . fields ) { assert ( t3 . fields . length === num * 2 ) ; } else { assert ( false ) ; } const t4 = ( res . blocks [ 18 ] as SectionBlock ) ; if ( t4 . fields ) { assert ( t4 . fields . length === num * 2 ) ; } else { assert ( false ) ; } assert ( ( res . blocks [ 22 ] as SectionBlock ) . text !== undefined ) ; } } ) ; } ) ; } ) ;