Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TYPEORM_PORT=3306
TYPEORM_USERNAME=cats
TYPEORM_PASSWORD=cats
TYPEORM_DATABASE=cats
TYPEORM_ENTITIES=dist/**/*.entity{.ts,.js}
PORT=3000
GOOGLE_CLIENT_ID=TODO: replace me
GOOGLE_SECRET=TODO: replace me
Expand Down
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ TYPEORM_PORT=
TYPEORM_USERNAME=
TYPEORM_PASSWORD=
TYPEORM_DATABASE=
TYPEORM_ENTITIES=dist/**/*.entity{.ts,.js}
PORT=
GOOGLE_CLIENT_ID=
GOOGLE_SECRET=
PUBLIC_KEY=keys/public.key
PRIVATE_KEY=keys/private.key
PRIVATE_KEY=keys/private.key
1 change: 1 addition & 0 deletions .env.github
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TYPEORM_PORT=3306
TYPEORM_USERNAME=root
TYPEORM_PASSWORD=root
TYPEORM_DATABASE=cats
TYPEORM_ENTITIES=dist/**/*.entity{.ts,.js}
PORT=3000
GOOGLE_CLIENT_ID=TODO: replace me
GOOGLE_SECRET=TODO: replace me
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TYPEORM_PORT=3306
TYPEORM_USERNAME=cats
TYPEORM_PASSWORD=cats
TYPEORM_DATABASE=cats
TYPEORM_ENTITIES=dist/**/*.entity{.ts,.js}
PORT=3000
GOOGLE_CLIENT_ID=TODO: replace me
GOOGLE_SECRET=TODO: replace me
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE cats' -uroot -proot
mysql -uroot -proot -D cats <test-data.sql
- run: ssh-keygen -f keys/key -N ""
- run: mv keys/key keys/private.key
- run: mv keys/key.pub keys/public.key
- run: npm run build:test
- run: cp .env.github .env.test
- run: npm run fixtures:load
- run: npm run test:integration
- run: echo "🍏 This job's status is ${{ job.status }}."
2 changes: 1 addition & 1 deletion cypress/integration/users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ describe('Backend API', () => {
it('verify the request returns 50 items', () => {
cy.request('http://localhost:3000/users')
.its('body')
.should('have.length', 0)
.should('have.length', 1)
})
})
13 changes: 0 additions & 13 deletions ormconfig-fixtures.json

This file was deleted.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@nestjs/schematics": "8.0.3",
"@nestjs/testing": "8.0.11",
"@types/express": "4.17.13",
"@types/faker": "^5.5.8",
"@types/jest": "^27.0.2",
"@types/js-sha512": "^0.8.0",
"@types/jsonwebtoken": "^8.5.5",
Expand Down
4 changes: 3 additions & 1 deletion src/entity/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class User extends BaseEntity {
@Column({ default: true })
isActive: boolean

@OneToMany(() => RefreshToken, (refresh_token) => refresh_token.user)
@OneToMany(() => RefreshToken, (refresh_token) => refresh_token.user, {
nullable: true,
})
refreshTokens: RefreshToken[]

public checkPassword(password: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/typeorm-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
username: process.env.TYPEORM_USERNAME,
password: process.env.TYPEORM_PASSWORD,
database: process.env.TYPEORM_DATABASE,
entities: [process.env.TYPEORM_ENTITIES],
autoLoadEntities: true,
entities: [__dirname + './dist/entity/*.js'],
synchronize: true,
}
}
Expand Down
132 changes: 132 additions & 0 deletions test-data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
-- MySQL dump 10.13 Distrib 8.0.26, for Linux (x86_64)
--
-- Host: localhost Database: cats
-- ------------------------------------------------------
-- Server version 8.0.26-0ubuntu1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `cat`
--

DROP TABLE IF EXISTS `cat`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `cat` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`age` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `cat`
--

LOCK TABLES `cat` WRITE;
/*!40000 ALTER TABLE `cat` DISABLE KEYS */;
INSERT INTO `cat` VALUES (1,'name3',5),(2,'name4',6),(3,'name5',6);
/*!40000 ALTER TABLE `cat` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `migrations`
--

DROP TABLE IF EXISTS `migrations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `migrations` (
`id` int NOT NULL AUTO_INCREMENT,
`timestamp` bigint NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `migrations`
--

LOCK TABLES `migrations` WRITE;
/*!40000 ALTER TABLE `migrations` DISABLE KEYS */;
INSERT INTO `migrations` VALUES (14,1595512047501,'Initial1595512047501'),(15,1595771506586,'RefreshToken1595771506586');
/*!40000 ALTER TABLE `migrations` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `refresh_token`
--

DROP TABLE IF EXISTS `refresh_token`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `refresh_token` (
`refreshToken` varchar(255) NOT NULL,
`userId` int DEFAULT NULL,
`expiresAt` datetime NOT NULL,
PRIMARY KEY (`refreshToken`),
KEY `FK_8e913e288156c133999341156ad` (`userId`),
CONSTRAINT `FK_8e913e288156c133999341156ad` FOREIGN KEY (`userId`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `refresh_token`
--

LOCK TABLES `refresh_token` WRITE;
/*!40000 ALTER TABLE `refresh_token` DISABLE KEYS */;
/*!40000 ALTER TABLE `refresh_token` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user`
--

DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user` (
`firstName` varchar(255) NOT NULL,
`lastName` varchar(255) NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`salt` varchar(255) NOT NULL,
`isActive` tinyint NOT NULL DEFAULT '1',
`id` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES ('First','Last','firstsecond','f5434636391ba298de1a7693cb5ae690170e7324dc96a6fc429e2b3208e78e3edf7f3ee14191de13d89fc479b6906997ac0114d36e3cfb991d210a8d8acae59a','htpQ5RMDQZKHdmu9HwbJvL7EuVvi/2oGWcmVtPNGJsPAnKzoGfpE8lpFy+tJC4h8olCrWVWExyA0sMFW6Ytb+g==',1,3);
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-10-25 17:53:47