How to test login with verification code?

  node.js, question

1. I developed the project with koa and tested it with mocha and supertest. Both login and registration have verification codes, and the verification codes exist in the Session. If I want to test, I have to get the verification code to pass the test. My Session is cookie-based, but cookies are encrypted. I can get cookies, but I still can’t get the value.
At present, I can think of ways:
1 > develop a new interface’ /getCaptcha’, and return the code in the session to me so that I can test it.
2 > For capthca Hard coding, a value, such as’ aaaa’, if equal to’ aaaa’, is verified.
I don’t feel very good about either. I’d better have direct access to the session.

The simplified code is posted below.

app.js

var app = module.exports =require('koa')();
 var router = require('koa-router')();
 var session = require('koa-session');
 var parse = require('co-body');
 app.keys = 'segmentfault';
 app.use(session(app));
 Get ('/captcha', function () {//write session
 this.session.captcha = getRandom(4);  //Random number, analog graphic verification code or SMS Verification Code
 this.body = {
 success:true
 bracket
 });
 
 router.post('/doLogin',function(){
 var params = yield parse(this);
 if(params.capthca !  = this.session.captcha){
 this.body = {
 success:false,
 Msg:' Mobile phone verification code error'
 bracket
 return;
 bracket
 
 //omit checking account password
 this.body= {
 success:true,
 Msg:' Login Successful'
 bracket
 
 
 })

test.js

var app = require('../app');  //is the above file
 var request = require('supertest').agent(app.listen());
 
 describe('test login',function(){
 it('get the capthca code',function(){
 request.get('/captcha').expect(200).end(function(err,res){
 sid =  res.headers['set-cookie'].pop().split(';'  )//cookie is available but encrypted, so login cannot be submitted
 })
 
 
 })
 });

Define debug mode, allow to turn off verification code or allow to customize right and wrong verification code