import { Test } from '@nestjs/testing'
import { WeixinService } from './weixin.service'
import { WeixinModule } from './weixin.module'
import { AppModule } from '../app.module'
import { ConfigModule } from '@nestjs/config'
import { TypeOrmModule } from '@nestjs/typeorm'
import weixinConfig from './weixin.config'
import { AccessTokenCache } from './entities/access-token-cache.entity'
import { JsapiTicketCache } from './entities/jsapi-ticket-cache.entity'

describe('WeixinService', () => {
    let weixinService: WeixinService

    beforeEach(async () => {
        const moduleRef = await Test.createTestingModule({
            imports: [
                AppModule,
                ConfigModule.forFeature(weixinConfig),
                TypeOrmModule.forFeature([AccessTokenCache, JsapiTicketCache])
            ],
            controllers: [],
            providers: [WeixinService]
        }).compile()

        weixinService = moduleRef.get<WeixinService>(WeixinService)
    })

    describe('getRedirectUrl', () => {
        it('getRedirectUrl', async () => {
            expect(weixinService).toBeDefined()
            console.log(weixinService.getRedirectUrl('https://www.baidu.com'))
        })
    })
})
