我是 cypress 的新手,我想知道如何进行以下检查:我有一个案例:我在数据库中有一个产品,可以有状态:InStock、OutOfStock 和 Discontinued。如果产品处于“InStock”状态,我应该能够将其发送给客户,如果处于“OutOfStock”/“Discontinued”状态,我应该无法发送给客户。通过 API 调用,我可以将产品发送给客户。如果产品处于“InStock”状态,则 API 响应为 200,否则响应为 statusCode 400。所以我的问题是:如何为每个测试更改数据库中产品的状态,以便我可以检查3 种状态中的每一种(如果 API 返回正确的响应)?我知道如何检查 API 响应本身,但我不清楚如何更改数据库中产品的状态,
我有后端 API,它接受带有图像表单数据的 POST 方法,如下所示,

当使用上面的 Postman 时,一切正常。但是当我想在 Angular 中执行此操作时,它不起作用。
<!-- html template file -->
<input type="file" (change)="handleInputEvent($event)"/>
Run Code Online (Sandbox Code Playgroud)
import {Component, OnInit} from '@angular/core';
import {MyDearFishService} from '../../my-dear-fish.service';
@Component({
selector: 'app-upload',
templateUrl: './upload.component.html',
styleUrls: ['./upload.component.scss']
})
export class UploadComponent implements OnInit {
constructor(public service: MyDearFishService) {
}
ngOnInit() {
}
arrayOne(n: number): any[] {
return Array(n);
}
handleInputEvent($event) {
const image = $event.target.files[0];
this.service.recognizeFish(image);
}
}
Run Code Online (Sandbox Code Playgroud)
// My service file (using HttpClient):
const rootUrl = 'https://...../api';
public recognizeFish(image: File): Promise<any> {
return …Run Code Online (Sandbox Code Playgroud) 我的照片和标签对象有 DTO,如下所示:
export class PhotoDto {
readonly title: string
readonly file: string
readonly tags: TagDto[]
}
export class TagDto {
readonly name: string
}
Run Code Online (Sandbox Code Playgroud)
我使用PhotoDtoin myphoto.service.ts并最终使用 inphoto.controller.ts来创建照片:
// In photo.service.ts
async create(createPhotoDto: PhotoDto): Promise<PhotoEntity> {
// ...
return await this.photoRepo.create(createPhotoDto)
}
// In photo.controller.ts
@Post()
async create(@Body() createPhotoDto: PhotoDto): Promise<PhotoEntity> {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但是,API 主体中的输入应具有以下结构:
{
"title": "Photo Title",
"file": "/some/path/file.jpg",
"tags": [
{
"name": "holiday"
},
{
"name": "memories"
}
]
} …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序的一部分编写测试用例,其中包括应用程序重启。在应用程序重新启动窗口期间出现确认对话框,必须接受该对话框才能重新启动应用程序。现在我在 Cypress 中模拟这个有问题,所以我的问题是:
如何OK在赛普拉斯测试的窗口确认对话框中执行按钮操作?
先感谢您!
我用 Fastify 创建了一个 NestJs 项目,并为其创建了一个中间件,但我不知道如何向客户端发送响应,类似于我们在 Express 中的做法,任何帮助将不胜感激,谢谢!,这是我的中间件代码:
import {
Injectable,
NestMiddleware,
HttpException,
HttpStatus,
} from '@nestjs/common';
@Injectable()
export class LoggerMiddleware implements NestMiddleware {
use(req: any, res: any, next: Function) {
console.log('Request...', res);
// throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
next();
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用 Fastify 在 NestJS 中注入请求标头。
import { FastifyRequest, FastifyReply } from 'fastify'; // fastify types are not valid
@Injectable()
export class TracingMiddleware implements NestMiddleware {
use(req: any, res: any, next: () => void) {
console.log('MyRequestHeaderKey', req.headers['MyRequestHeaderKey']); // find out how to get a header
res.header('MyResponseHeaderKey', 'MyResponseHeaderValue'); // find out how to set headers
next();
}
}
Run Code Online (Sandbox Code Playgroud)
Nest 文档上没有 fastify 中间件的参考:https://docs.nestjs.com/middleware
我已阅读 fastify 文档但没有成功:https://www.fastify.io/docs/v1.13.x/Reply/ 和https://www.fastify.io/docs/v1.13.x/Request/
我想知道如何使用 AWS Cognito Ruby SDK 注册新用户。
到目前为止我已经尝试过:
输入
AWS_KEY = "MY_AWS_KEY"
AWS_SECRET = "MY_AWS_SECRET"
client = Aws::CognitoIdentityProvider::Client.new(
access_key_id: AWS_KEY,
secret_access_key: AWS_SECRET,
region: 'us-east-1',
)
resp = client.sign_up({
client_id: "4d2c7274mc1bk4e9fr******", # required
username: "test@test.com", # required
password: "Password23sing", # required
user_attributes: [
{
name: "app", # required
value: "my app name",
},
],
validation_data: [
{
name: "username", # required
value: "true",
},
]
})
Run Code Online (Sandbox Code Playgroud)
输出
Aws::CognitoIdentityProvider::Errors::NotAuthorizedException (Unable to verify secret hash for client 4d2c7274mc1bk4e9fr*****)
Run Code Online (Sandbox Code Playgroud)
参考
不了解如何编写和设置 ruby 3 RBS 类型检查。
假设我有一个类似的文件:
### file name: my_project/book.rb
class Book
def initialize(pages)
@pages = pages
end
def pages
@pages
end
end
first_book = Book.new(100)
puts first_book.pages
Run Code Online (Sandbox Code Playgroud)
问题:.rbs对于我的文件示例,文件应该是什么样的?我应该运行什么 CLI 命令来测试它?例如$rbs my_project *或类似的东西?
所以,我有一个 Rails 应用程序,安装了 webpacker、vue、turbolinks 和stimulus js。
我遇到的问题是,即使控制器只导入一次,即使我暂时禁用涡轮链接,该initialize()功能也会connect()被调用两次。
仅当我进行刷新时才会发生这种情况(即不是当我第一次访问该页面时,而是仅当我执行页面重新加载时)。
奇怪的是,disconnect()只被调用一次(当我离开页面时)
这很糟糕,因为我需要在初始化时修改 DOM,所以我添加了两次元素。有人知道造成这种情况的原因和/或解决方案吗?
编辑:按照要求的application.js
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
import "stylesheets"
import "controllers"
import "components"
Run Code Online (Sandbox Code Playgroud)
组件/index.js
import Vue from 'vue/dist/vue.esm'
import BootstrapVue from 'bootstrap-vue'
import TurbolinksAdapter from 'vue-turbolinks'
Vue.use(BootstrapVue)
Vue.use(TurbolinksAdapter)
const components = {}
const context = require.context("components", true, /_component\.vue$/)
context.keys().forEach(filename => {
const component_name = filename.replace(/^.*[\\\/]/, '').replace(/_component\.vue$/, '')
const component = context(filename).default
components[component_name] = component
})
document.addEventListener('turbolinks:load', () => {
const app = new Vue({
el: …Run Code Online (Sandbox Code Playgroud) 我的 Rails 版本升级有点晚了。让我惊讶的是 Rails 生成的 config/environment/* 文件中需要一堆 active_support 。
它们是做什么用的?这和Rails6中引入的Zeitwerk有什么关系吗?我不记得它们出现在旧版本的 Rails 中。
ag ^require config/environments
config/environments/development.rb
1:require "active_support/core_ext/integer/time"
config/environments/test.rb
1:require "active_support/core_ext/integer/time"
config/environments/production.rb
1:require "active_support/core_ext/integer/time"
Run Code Online (Sandbox Code Playgroud)
重现步骤:
rails new myapp
cat Gemfile | grep "^gem 'rails'"
gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
Run Code Online (Sandbox Code Playgroud)
我试图在 Rails/rails CHANGELOG 和一些 git blaiming 中找到此更新,但这没有帮助。
nestjs ×3
node.js ×3
cypress ×2
fastify ×2
ruby ×2
angular ×1
database ×1
form-data ×1
javascript ×1
rbs ×1
stimulusjs ×1
turbolinks ×1
typescript ×1
zeitwerk ×1