Skip to content

Commit

Permalink
Merge branch 'develop' into bg-fix-password-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
chialuka committed Aug 1, 2019
2 parents 6f0a887 + 452b993 commit 74cbb8c
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 0 deletions.
47 changes: 47 additions & 0 deletions server/database/migrations/20190731135151-create-session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export default {
up: (queryInterface, Sequelize) => queryInterface.createTable('Sessions', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
allowNull: false,
type: Sequelize.INTEGER
},
active: {
allowNull: false,
type: Sequelize.BOOLEAN,
defaultValue: true
},
devicePlatform: {
allowNull: false,
type: Sequelize.STRING,
defaultValue: 'browser'
},
expiresAt: {
allowNull: false,
type: Sequelize.DATE
},
ipAddress: {
type: Sequelize.STRING
},
token: {
allowNull: false,
type: Sequelize.STRING
},
userAgent: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Sessions')
};
1 change: 1 addition & 0 deletions server/database/models/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* istanbul ignore file */

import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
Expand Down
16 changes: 16 additions & 0 deletions server/database/models/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default (sequelize, DataTypes) => {
const Session = sequelize.define(
'Sessions',
{
userId: DataTypes.INTEGER,
active: DataTypes.BOOLEAN,
devicePlatform: DataTypes.STRING,
expiresAt: DataTypes.DATE,
ipAddress: DataTypes.STRING,
token: DataTypes.STRING,
userAgent: DataTypes.STRING
},
{}
);
return Session;
};
36 changes: 36 additions & 0 deletions server/database/seeds/20190731140725-demo-session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable max-len */
export default {
up: queryInterface => queryInterface.bulkInsert(
'Sessions',
[
{
userId: 1,
active: true,
devicePlatform: 'browser',
expiresAt: new Date('2020-10-10'),
ipAddress: '121.234.188.49',
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
userAgent:
'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36',
createdAt: new Date(),
updatedAt: new Date()
},
{
userId: 2,
active: true,
devicePlatform: 'browser',
expiresAt: new Date('2020-10-10'),
ipAddress: '121.234.200.49',
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
userAgent:
'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36',
createdAt: new Date(),
updatedAt: new Date()
}
],
{}
),
down: queryInterface => queryInterface.bulkDelete('Sessions', null, {})
};
3 changes: 3 additions & 0 deletions test/helpers/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sessionMigration from './sessionMigration.test';

export default { sessionMigration };
23 changes: 23 additions & 0 deletions test/helpers/sessionMigration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import chai, { expect } from 'chai';
import models from '../../server/database/models';

const { Sessions } = models;

describe('Session Model', () => {
it('Successfully insert into session database', async () => {
const session = await Sessions.create({
userId: 1,
active: true,
devicePlatform: 'browser',
expiresAt: new Date('2020-10-10'),
ipAddress: '121.234.188.49',
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
userAgent:
'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36'
});
expect(session).to.be.an('object');
});
});

export default chai;
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chai from 'chai';
import chaiHttp from 'chai-http';
import server from '../server';
import './helpers/index.test';
import './users';
import './middlewares/userValidation.test';

Expand Down

0 comments on commit 74cbb8c

Please sign in to comment.