小编aRt*_*too的帖子

Jest 测试通过但得到错误:最后连接 ECONNREFUSED 127.0.0.1:80

我在后端使用带有 TypeScript 的节点,在后端使用 Jest 和 Supertest 作为我的测试框架。

当我尝试测试时,结果通过了,但最后出现错误。结果如下:

 PASS  test/controllers/user.controller.test.ts
  Get all users
    ? should return status code 200 (25ms)

  console.log node_modules/@overnightjs/logger/lib/Logger.js:173
    [2019-12-05T04:54:26.811Z]: Setting up database ...

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.284s
Ran all test suites.
server/test/controllers/user.controller.test.ts:32
                throw err;
                ^

Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
npm ERR! Test failed.  See above for more details.
Run Code Online (Sandbox Code Playgroud)

这是我的测试代码:

import request from "supertest";
import { AppServer } from '../../config/server'; …
Run Code Online (Sandbox Code Playgroud)

testing node.js jestjs ts-jest

15
推荐指数
2
解决办法
2万
查看次数

如何在typeorm多对多关系中选择特定列

我与 TYPEORM 中的自定义联接表有 n:m 关系。

实体1

@Entity({ name: 'users' })
export class User extends BaseModel {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: 'varchar', length: 50 })
  @IsNotEmpty()
  username!: string;

  @Column({ unique: true, type: 'varchar', length: 50 })
  @IsEmail()
  @IsNotEmpty()
  email!: string;

  @CreateDateColumn({ type: 'timestamp' })
  createdAt!: Date;

  @UpdateDateColumn({ type: 'timestamp' })
  updatedAt!: Date;

  @DeleteDateColumn({ type: 'timestamp' })
  deletedAt!: Date;

  @OneToMany(
    (type) => UsersGameGroup,
    (userGameGroup) => userGameGroup.user,
    { cascade: true }
  )
  usersGameGroups!: UsersGameGroup[];
}
Run Code Online (Sandbox Code Playgroud)

实体2

@Entity({ name: 'game_groups' })
export class …
Run Code Online (Sandbox Code Playgroud)

typescript typeorm typeorm-activerecord

4
推荐指数
1
解决办法
1万
查看次数

删除具有上次修改日期条件的多个 s3 存储桶文件

如何删除具有上次修改日期条件的多个 S3 文件?

我在 s3 上有这个文件夹结构。

  • dentca 实验室开发样本
    • 2019-03-13
      • file1 最后修改时间:2019 年 3 月 13 日下午 2:34:06 GMT-0700
      • file2 最后修改时间:2019 年 3 月 13 日下午 3:18:01 GMT-0700
      • file3 最后修改时间:2019 年 3 月 13 日下午 2:34:30 GMT-0700
      • file4 最后修改时间:2019 年 3 月 13 日下午 2:32:40 GMT-0700

并想删除一个文件(这只是一个示例)小于 Mar 13, 2019 2:34:30 PM

所以我制作了这个 bash 脚本,但它不起作用。

aws s3 ls --recursive s3://dentca-lab-dev-sample/2019-03-13/ | awk '$1 <= "2019-03-13 14:34:30" {print $4}'

**ls仅用于测试。将其更改为rm

我也有这个脚本用于测试

aws s3 ls --recursive s3://dentca-lab-dev-sample/2019-03-13/

输出: …

bash amazon-s3 amazon-web-services

3
推荐指数
1
解决办法
7869
查看次数

如何在 TypeORM 上使用 onDelete: 'CASCADE'

我有 2 个迁移用户和帖子,并且帖子有一个onDelete: 'CASCADE'. 由于某种原因,当我删除带有帖子的用户时,它会抛出错误:

"Cannot delete or update a parent row: a foreign key constraint fails (`development_db`.`posts`, CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `users` (`id`))",
Run Code Online (Sandbox Code Playgroud)

但我已经将我的 Posts 实体设置为onDelete: 'CASCADE'. 让我失望的是,当我ON DELETE CASCADE在帖子迁移上添加时,级联删除仍然有效,即使我onDelete: 'CASCADE'在帖子模型上删除了。任何想法?onDelete那么,当您可以在迁移上而不是在实体上设置它但仍然有效时,在 typeorm 中有什么用呢?

用户迁移:

"Cannot delete or update a parent row: a foreign key constraint fails (`development_db`.`posts`, CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `users` (`id`))",
Run Code Online (Sandbox Code Playgroud)

后迁移:

/* eslint-disable class-methods-use-this */
import { MigrationInterface, QueryRunner } from 'typeorm'; …
Run Code Online (Sandbox Code Playgroud)

typeorm typeorm-activerecord

1
推荐指数
1
解决办法
9478
查看次数