How to simulate the ctx.session information in koa-session when testing with jest?

while learning to test api with jest, I encountered this function:

const checkHasLogin = async (ctx, next) => {
  if (ctx.session.userName) {
    ctx.body = {
      success: true,
      msg: ctx.session.userName
    }
  } else {
    ctx.body = {
      success: false,
      msg: ""
    }
  }
}

where ctx.session is:

// app.js
const session = require("koa-session")
const CONFIG = {
  key: "koa:todo",
  maxAge: 86400000,
  overwrite: true,
  httpOnly: true,
  signed: true,
  rolling: false,
  renew: false
}
app.use(session(CONFIG, app))

I"d like to ask if there is any way to simulate this ctx.session .

// 
test("user login if session.userName is exist", async () => {
  const res = await request(app.callback())
    .get("/api/login/hasLogin")
  expect(res.body.success).toBe(true)
})
Dec.31,2021

test('user login if session.userName is exist', async () => {
    const res = await request(app.callback())
      .get('/api/login/hasLogin')
      .set('cookie', 'koa:todo=eyJ1c2VyTmFtZSI6Imhpd29ybGQiLCJfZXhwaXJlIjoxNTQzNzM5NjU1ODkwLCJfbWF4QWdlIjo4NjQwMDAwMH0=; koa:todo.sig=Op3Ik5vbgl-IsFuGC8i_u6MRgyk')
    expect(res.body.success).toBe(true)
  })

create a test cookie, to solve.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b3b8-2a7c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b3b8-2a7c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?