[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 ...
随机推荐
- 技术报告:APT组织Wekby利用DNS请求作为C&C设施,攻击美国秘密机构
技术报告:APT组织Wekby利用DNS请求作为C&C设施,攻击美国秘密机构 最近几周Paloalto Networks的研究人员注意到,APT组织Wekby对美国的部分秘密机构展开了一次攻击 ...
- lvs为何不能完全替代DNS轮询--转
原文地址:http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651959595&idx=1&sn=5f0633afd2 ...
- 解决Visual Studio-IIS Express 支持局域网访问
- 在C# 获取当前应用网址
/// <summary> /// 获取当前应用网址 /// </summary> /// <returns></r ...
- [Chromium文档转载,第005章]Calling Mojo from Blink
For Developers > Design Documents > Mojo > Calling Mojo from Blink Variants Let's as ...
- js数组中foEach和map的用法详解 jq中的$.each和$.map
数组中foEach和map的用法详解 相同点: 1.都是循环遍历数组(仅仅是数组)中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项value, ...
- U-BOOT启动流程分析--start.s(二)
一.概述 u-boot的启动流程: 从文件层面上看主要流程是在两个文件中:cpu/arm920t/start.s,lib_arm/board.c, 先来分析start.s 在flash中执行的引 ...
- iscsi共享存储的简单配置和应用
1.环境介绍 SCSI(Small Computer System Interface)是块数据传输协议,在存储行业广泛应用,是存储设备最基本的标准协议.从根本上说,iSCSI协议是一种利用IP网络来 ...
- sparkR处理Gb级数据集
spark集群搭建及介绍:敬请关注 数据集:http://pan.baidu.com/s/1sjYN7lF 总结:使用sparkR进行数据分析建模相比R大致有3-5倍的提升 查看原始数据集:通过iri ...
- SQL解析器的性能測试
对同一个sql语句,使用3种解析器解析出ast语法树(这是编译原理上的说法,在sql解析式可能就是解析器自己定义的statement类型).运行100万次的时间对照. package demo.tes ...