[Node & Tests] Intergration tests for Authentication
For intergration tests, always remember when you create a 'mass' you should aslo clean up the 'mass'.
For example when you start the server, you need to close the server after the tests. See the post: http://www.cnblogs.com/Answer1215/p/7554662.html
Also for authentication, when you create a new user for testing, you should also clean it up.
There is a help function for tests, to create a new user:
async function createNewUser(overrides) {
const password = faker.internet.password()
const userData = generateUserData(overrides)
const {email, username} = userData
const user = await api
.post('users', {user: {email, password, username}})
.then(getUser)
return {
user,
cleanup() {
return api.delete(`users/${user.username}`)
},
}
}
In the return value, it also provide a function to clean up the user.
const api = axios.create({
baseURL: 'http://localhost:3000/api',
}) describe('authenticated', () => {
let cleanupUser
beforeAll(async () => {
const results = await createNewUser()
cleanupUser = results.cleanup
api.defaults.headers.common.authorization = `Token ${results.user.token}` // set default http header, add authorization for JWT token
}) afterAll(async () => {
await cleanupUser()
api.defaults.headers.common.authorization = ''
}) })
[Node & Tests] Intergration tests for Authentication的更多相关文章
- [Node & Testing] Intergration Testing with Node Express
We have express app: import _ from 'lodash' import faker from 'faker' import express from 'express' ...
- How to: Run Tests from Microsoft Visual Studio
https://msdn.microsoft.com/en-us/library/ms182470.aspx Running Automated Tests in Visual Studio Visu ...
- C# Note37: Writing unit tests with use of mocking
前言 What's mocking and its benefits Mocking is an integral part of unit testing. Although you can run ...
- Tests for normality正态分布检验
欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章 sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/ ...
- 自动化运维工具Ansible之Tests测验详解
Ansible Tests 详解与使用案例 主机规划 添加用户账号 说明: 1. 运维人员使用的登录账号: 2. 所有的业务都放在 /app/ 下「yun用户的家目录」,避免业务数据乱放: 3. 该用 ...
- crtmpserver实现防盗流和流推送验证
Protecting your streams from webpage copy&paste flash code, listing or recording 保护流,防止在页面上被复制&a ...
- crtmpserver实现防盗流和流推送验证 之二
IV. Catching the thieves 抓住小偷 Well, we have just added a secure mechanism to our little streaming se ...
- OPENVPN2.3配置文档官方说明
openvpn Section: Maintenance Commands (8)Index NAME openvpn - secure IP tunnel daemon. SYNOPSIS open ...
- hbase官方文档(转)
FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南 HBase 官方文档中文版 Copyright © 2012 Apache Soft ...
随机推荐
- POJ2823 单调队列
POJ2823 http://poj.org/problem?id=2823 最基础的单调队列,说是数据结构,其实就是一种更新数组数据的方法. 之前还准备用deque,超时了,直接head,tail快 ...
- HUE配置文件hue.ini 的filebrowser模块详解(图文详解)(分HA集群和非HA集群)
不多说,直接上干货! 我的集群机器情况是 bigdatamaster(192.168.80.10).bigdataslave1(192.168.80.11)和bigdataslave2(192.168 ...
- 外部数据库驱动程序XX中的意外错误
链接EXCEL打开报错 代码如下(Excel2003版本)出现这种错误 现在只需要更改 修改成 并且把导入版本修改
- ZOJ 3435 Ideal Puzzle Bobble 莫比乌斯反演
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4119 依然是三维空间内求(1,1,1)~(a,b,c)能看到的整点数,平移一下 ...
- python 多线程学习小记
python对于thread的管理中有两个函数:join和setDaemon setDaemon:如果在程序中将子线程设置为守护线程,则该子线程会在主线程结束时自动退出,设置方式为thread.set ...
- <QT之Bug制造机>QT中串口类“QSerialPort”的学习笔记
QT5中已经增加了串口类QSrialPort,可以直接调用API函数进行快速开发. 1. 获取串口信息 Dialog::Dialog(QWidget *parent) : QDialog(parent ...
- 小试VS 2017 开发Python Django项目过程一
一.新建项目python ->django web 项目 (选择带bootstrap风格与twwriter)项目名称iepiececomputing (ie计件计算)跳出窗体 -> 添加虚 ...
- CODEVS——T1052 地鼠游戏
http://codevs.cn/problem/1052/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 D ...
- amaze ui响应式辅助
amaze ui响应式辅助 响应式辅助 就是不同的显示屏幕,或者手机的横竖屏,你可以控制栏目的显影,还是挺有帮助的 视口大小 .am-[show|hide]-[sm|md|lg][-up|-down| ...
- ElasticSearch 架构图
ElasticSearch 架构图 从下往上来分析ElasticSearch 架构图 Gateway代表ElasticSearch索引的持久化存储方式. 在Gateway中,ElasticSearch ...