node.js - 如何使用 dynamodb 查询操作模拟/单元测试分页?
问题描述
我已经成功地实现了向前/向后分页以及使用 dynamoDb 查询在后端进行排序。但是我一直坚持提供分页数据或排序数据。
有没有办法在测试期间加载虚拟数据?
我的测试代码
test('should paginate backward and forward', async () => {
const data = {
Items: [
{
convertedUrl: 'https://xxxx.awssensei.tk/ddddd',
createdAt: '2021-11-04T05:50:14.180Z',
originalUrl: 'https://aws.com',
updatedAt: '2021-11-04T05:58:12.659Z',
},
{
convertedUrl: 'https://xxxx.awssensei.tk/bbbbb',
createdAt: '2021-11-04T05:50:43.818Z',
originalUrl: 'https://fb.com',
updatedAt: '2021-11-04T05:57:42.704Z',
},
{
convertedUrl: 'https://xxx.awssensei.tk/eeeee',
createdAt: '2021-11-04T05:50:55.121Z',
originalUrl: 'https://google.com',
updatedAt: '2021-11-04T05:58:21.141Z',
},
{
convertedUrl: 'https://xxxx.awssensei.tk/aaaaa',
createdAt: '2021-11-04T05:51:06.603Z',
originalUrl: 'https://instagram.com',
updatedAt: '2021-11-04T05:57:14.750Z',
},
],
};
sandbox
.stub(AWS.DynamoDB.DocumentClient.prototype, 'query')
.returns({ promise: () => data });
const app = require('../app');
const response = await request(app)
.get('/users/auth-user/urls?sort_by=createdAt')
.set('Authorization', `Bearer ${token}`);
expect(response.body.history.length).toBe(4);
});
解决方案
推荐阅读
- android - 使用 ImageSliders Image 通过 Intent 上传电子邮件中的图像
- java - 我正在使用 springframework 中的@PathVariable。当我尝试从控制器返回视图页面名称时,出现 404 错误
- hibernate - 使用休眠 5.1.2 版本降低性能
- javascript - 如何在界面中使用对象键?
- java - 我如何实现声纳+故障安全+jacoco?
- validation - 根据另一个参考架构验证 GraphQL 架构
- openlayers - OpenLayers 5 RegularShape 特征从指定坐标偏移
- ios - 可选的
到 Int64 为零,硬编码它可以工作 - python - 将小数据框附加到大数据框并对其进行排序
- amazon-web-services - 在单个 DynamoDB 表上使用多个全局索引是否有效?