Skip to content

Commit ca2cee7

Browse files
authored
Merge pull request #24 from x-team/feature/XTG-248-change-gametypeid
Feature/xtg 248 change gametypeid to Int
2 parents dfcf85a + a8b87f8 commit ca2cee7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+726
-258
lines changed

.env.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# API
2+
HOST=0.0.0.0
3+
PORT=3000
4+
5+
# DATABASE
6+
DB_USERNAME=postgres
7+
DB_PASSWORD=*games-2021
8+
DB_NAME=gameshq_api_test
9+
DB_HOSTNAME=127.0.0.1
10+
DB_PORT=5435

docker-compose-test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3.7'
2+
3+
services:
4+
gameshq_api_db_test:
5+
image: postgres:10-alpine
6+
ports:
7+
- '5435:5432'
8+
environment:
9+
POSTGRES_USER: 'postgres'
10+
POSTGRES_DB: 'gameshq_api_test'
11+
POSTGRES_PASSWORD: '*games-2021'
12+
volumes:
13+
- postgres:/var/lib/postgresql/data
14+
networks:
15+
- gameshq_api_db_test_network
16+
volumes:
17+
postgres:
18+
19+
networks:
20+
gameshq_api_db_test_network:

migrate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env ts-node-script
22

33
import { Sequelize } from 'sequelize';
4-
import { Umzug, SequelizeStorage, MigrationMeta } from 'umzug';
4+
import type { MigrationMeta } from 'umzug';
5+
import { Umzug, SequelizeStorage } from 'umzug';
6+
57
import { sequelizeConfig } from './src/db';
68

79
const sequelize = new Sequelize({ ...sequelizeConfig, logging: undefined });

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": "cross-env NODE_ENV=test ENV=test npm run test:all",
1111
"test:integration": "cross-env NODE_ENV=test ENV=test npm run test:_integration",
1212
"test:integration:single": "cross-env NODE_ENV=test ENV=test npm run test:prepare:integration && npm run mocha",
13-
"test:unit": "cross-env NODE_ENV=test ENV=test npm run mocha \"src/**/*.test.ts\" --exclude \"src/**/*.integration.test.ts\"",
13+
"test:unit": "cross-env NODE_ENV=test ENV=test npm run mocha \"test/**/*.test.ts\" --exclude \"test/**/*.integration.test.ts\"",
1414
"test:unit:single": "cross-env NODE_ENV=test ENV=test npm run mocha",
1515
"mocha": "cross-env ENV=test mocha --unhandled-rejections=strict",
1616
"eslint": "eslint src --fix",
@@ -25,13 +25,12 @@
2525
"//1": "/*****************************************************************************",
2626
"//2": "* Rest of those commands are used internally and should not be used directly!",
2727
"//3": "*****************************************************************************/",
28-
"prepare-db": "npm run db:seed:up && npm run db:migrate:up",
28+
"prepare-db": "echo preparing db for $NODE_ENV env && npm run db:seed:up && npm run db:migrate:up",
2929
"clean": "rm -rf dist",
30-
"db:test:create": "cross-env NODE_ENV=test ENV=test sequelize --config='src/config/database.ci.js' db:create || true",
31-
"db:test:drop": "cross-env NODE_ENV=test ENV=test sequelize --config='src/config/database.ci.js' db:drop || true",
30+
"db:test:create": "docker-compose -p gameshq-api-test-project -f 'docker-compose-test.yml' up -d",
3231
"test:all": "concurrently --kill-others-on-fail --names *typescript,*****eslint,*tests:unit,integration --prefix-colors blue.inverse,blue,yellow,green 'npm run tsc' 'npm run eslint --quiet' 'npm run test:unit' 'npm run test:integration'",
33-
"test:prepare:integration": "npm run db:test:drop && npm run db:test:create && npm run prepare-db",
34-
"test:_integration": "npm run test:prepare:integration && npm run mocha \"src/**/*.integration.test.ts\"",
32+
"test:prepare:integration": "npm run db:test:create && cross-env NODE_ENV=test ENV=test npm run prepare-db",
33+
"test:_integration": "npm run test:prepare:integration && npm run mocha \"test/**/*.integration.test.ts\"",
3534
"prepare": "husky install"
3635
},
3736
"author": "X-Team Community",

src/api-utils/responseSchemas/gamedev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Joi from 'joi';
22

33
const gameItemSchema = Joi.object({
4-
// Pending due to new table design
5-
id: Joi.string(),
4+
id: Joi.number(),
5+
name: Joi.string(),
66
clientSecret: Joi.string(),
77
signingSecret: Joi.string(),
88
_createdById: Joi.number(),

src/api-utils/responseSchemas/user.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const sessionTokenSchema = Joi.object({
1212
const userSessionSchema = Joi.object({
1313
displayName: Joi.string().required(),
1414
email: Joi.string().email().required(),
15-
slackId: Joi.string().optional(),
16-
firebaseUserUid: Joi.string().optional(),
17-
profilePictureUrl: Joi.string().optional(),
15+
slackId: Joi.string().allow(null).optional(),
16+
firebaseUserUid: Joi.string().allow(null).optional(),
17+
profilePictureUrl: Joi.string().allow(null).optional(),
1818
role: Joi.number().required(),
1919
isAdmin: Joi.boolean().required(),
2020
}).options({ stripUnknown: true });
2121

22-
const sessionSchema = Joi.object({
22+
export const sessionSchema = Joi.object({
2323
success: sessionStateSchema,
2424
session: sessionTokenSchema,
2525
user: userSessionSchema,

src/config/database.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const dotenv = require('dotenv');
22
const { getConfig } = require('./index');
33

4-
if (getConfig('NODE_ENV') !== 'production') {
4+
if (getConfig('NODE_ENV') === 'test') {
5+
dotenv.config({ path: '.env.test' });
6+
} else if (getConfig('NODE_ENV') !== 'production') {
57
dotenv.config({ path: '.env.dev' });
68
}
79

@@ -19,7 +21,6 @@ module.exports = {
1921
development: config,
2022
test: {
2123
...config,
22-
database: `${config.database}_test`,
2324
seederStorage: 'none',
2425
},
2526
production: config,

src/games/arena/repositories/arena/actions/admin/create-or-finish-game.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from '../../../../../../models';
1+
import type { User } from '../../../../../../models';
22
import { findActiveArenaGame, startArenaGame } from '../../../../../../models/ArenaGame';
33
import { activateAllArenaZones } from '../../../../../../models/ArenaZone';
44
import { enableAllItems } from '../../../../../../models/GameItemAvailability';
@@ -38,7 +38,7 @@ export async function newGame(commandText: string, userRequesting: User) {
3838
transaction
3939
);
4040

41-
await enableAllItems(GAME_TYPE.ARENA, transaction);
41+
await enableAllItems(game._gameTypeId, transaction);
4242
return getGameResponse(arenaCommandReply.adminCreatedGame(game));
4343
});
4444
}
@@ -68,7 +68,7 @@ export async function endGame(userRequesting: User) {
6868
if (!game) {
6969
return getGameError(arenaCommandReply.noActiveGame());
7070
}
71-
await enableAllItems(GAME_TYPE.ARENA, transaction);
71+
await enableAllItems(game._gameTypeId, transaction);
7272
await game.endGame(transaction);
7373
await activateAllArenaZones(transaction);
7474
await publishArenaMessage(arenaCommandReply.channelEndGame(game), true);

src/games/arena/repositories/arena/actions/admin/revive-boss.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from '../../../../../../models';
1+
import type { User } from '../../../../../../models';
22
import { findPlayerByUser } from '../../../../../../models/ArenaPlayer';
33
import { findActiveRound } from '../../../../../../models/ArenaRound';
44
import { getUserBySlackId } from '../../../../../../models/User';

src/games/arena/repositories/arena/actions/admin/start-round.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from '../../../../../../models';
1+
import type { User } from '../../../../../../models';
22
import { findLivingPlayersByGame } from '../../../../../../models/ArenaPlayer';
33
import {
44
countRoundsCompleted,

0 commit comments

Comments
 (0)