perarnborg / vuex-oidc

Vuejs (with vuex) wrapper for open id authentication
MIT License
232 stars 64 forks source link

How to mock vuexoidc events to test listeners #163

Closed WaldemarEnns closed 1 year ago

WaldemarEnns commented 3 years ago

Hello there,

I would like to dispatch the event userLoaded to test my event listener for that event. How can I do that in jest? I was looking for some help in the code itself but couldn't find anything.

Thanks in advance!

perarnborg commented 3 years ago

Hello, sorry for this late reply.

Most of the events are defined in https://github.com/IdentityModel/oidc-client-js and just passed through by vuex-oidc. So if you want to look in the I would point you there in stead.

I believe a stub of the userLoaded event could look something like this:

{
   detail: {
      "id_token":"eyJhbGci...",
      "access_token":"...",
      "token_type":"Bearer",
      "scope":"email openid https://www.googleapis.com/auth/userinfo.email",
      "profile":{
         "azp":"...",
         "sub":"...",
         "hd":"perarnborg.se",
         "email":"kontakt@perarnborg.se",
         "email_verified":true,
         "jti":"...",
         "name":"Per Arnborg",
         "given_name":"Per",
         "family_name":"Arnborg",
         "picture":"https://lh3.googleusercontent.com/a-/AOh14GhI7JgSfRS375esLWgVErrH53L_rUqx5lQAfMrG=s96-c"
      },
      "expires_at":1623483881
   }
}