Skip to content

Commit

Permalink
1709-migration-script
Browse files Browse the repository at this point in the history
  • Loading branch information
basarbk committed Aug 11, 2020
1 parent 1f3b1a4 commit fd8f402
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 64 deletions.
7 changes: 0 additions & 7 deletions __tests__/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ const request = require('supertest');
const app = require('../src/app');
const User = require('../src/user/User');
const Token = require('../src/auth/Token');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await User.destroy({ truncate: { cascade: true } });
});
Expand Down
7 changes: 0 additions & 7 deletions __tests__/FileUpload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ const request = require('supertest');
const app = require('../src/app');
const path = require('path');
const FileAttachment = require('../src/file/FileAttachment');
const sequelize = require('../src/config/database');
const fs = require('fs');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');
const config = require('config');

const { uploadDir, attachmentDir } = config;

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await FileAttachment.destroy({ truncate: true });
});
Expand Down
7 changes: 0 additions & 7 deletions __tests__/HoaxListing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ const app = require('../src/app');
const User = require('../src/user/User');
const Hoax = require('../src/hoax/Hoax');
const FileAttachment = require('../src/file/FileAttachment');
const sequelize = require('../src/config/database');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await FileAttachment.destroy({ truncate: true });
await User.destroy({ truncate: { cascade: true } });
Expand Down
7 changes: 0 additions & 7 deletions __tests__/HoaxSubmit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ const tr = require('../locales/tr/translation.json');
const User = require('../src/user/User');
const Hoax = require('../src/hoax/Hoax');
const FileAttachment = require('../src/file/FileAttachment');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const path = require('path');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await FileAttachment.destroy({ truncate: true });
await User.destroy({ truncate: { cascade: true } });
Expand Down
4 changes: 0 additions & 4 deletions __tests__/PasswordReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const request = require('supertest');
const app = require('../src/app');
const User = require('../src/user/User');
const Token = require('../src/auth/Token');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');
Expand Down Expand Up @@ -34,9 +33,6 @@ beforeAll(async () => {

await server.listen(config.mail.port, 'localhost');

if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
jest.setTimeout(20000);
});

Expand Down
7 changes: 0 additions & 7 deletions __tests__/TokenService.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const sequelize = require('../src/config/database');
const Token = require('../src/auth/Token');

const TokenService = require('../src/auth/TokenService');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await Token.destroy({ truncate: true });
});
Expand Down
7 changes: 0 additions & 7 deletions __tests__/UserDelete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ const app = require('../src/app');
const User = require('../src/user/User');
const Token = require('../src/auth/Token');
const Hoax = require('../src/hoax/Hoax');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await User.destroy({ truncate: { cascade: true } });
});
Expand Down
7 changes: 0 additions & 7 deletions __tests__/UserListing.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
const request = require('supertest');
const app = require('../src/app');
const User = require('../src/user/User');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await User.destroy({ truncate: { cascade: true } });
});
Expand Down
4 changes: 0 additions & 4 deletions __tests__/UserRegister.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const request = require('supertest');
const app = require('../src/app');
const User = require('../src/user/User');
const sequelize = require('../src/config/database');
const SMTPServer = require('smtp-server').SMTPServer;
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');
Expand Down Expand Up @@ -32,9 +31,6 @@ beforeAll(async () => {

await server.listen(config.mail.port, 'localhost');

if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
jest.setTimeout(20000);
});

Expand Down
7 changes: 0 additions & 7 deletions __tests__/UserUpdate.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const request = require('supertest');
const app = require('../src/app');
const User = require('../src/user/User');
const sequelize = require('../src/config/database');
const bcrypt = require('bcrypt');
const en = require('../locales/en/translation.json');
const tr = require('../locales/tr/translation.json');
Expand All @@ -12,12 +11,6 @@ const config = require('config');
const { uploadDir, profileDir } = config;
const profileDirectory = path.join('.', uploadDir, profileDir);

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}
});

beforeEach(async () => {
await User.destroy({ truncate: { cascade: true } });
});
Expand Down
35 changes: 35 additions & 0 deletions database/migrations/20200811194140-create-file-attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('fileAttachments', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
filename: {
type: Sequelize.STRING,
},
uploadDate: {
type: Sequelize.DATE,
},
fileType: {
type: Sequelize.STRING,
},
hoaxId: {
type: Sequelize.INTEGER,
references: {
model: 'hoaxes',
key: 'id',
},
},
});
},

// eslint-disable-next-line no-unused-vars
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('fileAttachments');
},
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/config/"
],
"setupFilesAfterEnv": [
"<rootDir>/test-setup.js"
]
}
}
10 changes: 10 additions & 0 deletions test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const FileAttachment = require('./src/file/FileAttachment');
const sequelize = require('./src/config/database');

beforeAll(async () => {
if (process.env.NODE_ENV === 'test') {
await sequelize.sync();
}

await FileAttachment.destroy({ truncate: true });
});

0 comments on commit fd8f402

Please sign in to comment.