forked from CodeForPoznan/alinka-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeForPoznan#121] Added school model, refactor code, fixtures and s…
…imple test
- Loading branch information
Showing
13 changed files
with
99 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = [ | ||
"przedszkole", | ||
"szkoła podstawowa", | ||
"szkoła zawodowa", | ||
"liceum ogólnokształcące" | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { School } = require("../../db/models"); | ||
const schoolTypeList = require("../../db/school_types"); | ||
const faker = require("faker/locale/pl"); | ||
|
||
const schoolData = () => { | ||
const schoolType = faker.random.arrayElement(schoolTypeList); | ||
return { | ||
type: schoolType, | ||
name: `${schoolType} nr. ${faker.random.number(200)}`, | ||
city: faker.address.city(), | ||
postCode: faker.address.zipCode(), | ||
street: faker.address.streetAddress() | ||
}; | ||
}; | ||
|
||
const schoolFixture = async (props = {}) => { | ||
const schoolData = schoolData(); | ||
return await School.create({ schoolData, ...props }); | ||
}; | ||
|
||
module.exports = schoolFixture; | ||
module.exports.schoolData = schoolData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
const SchoolType = require("../../db/models"); | ||
const { SchoolType } = require("../../db/models"); | ||
const schoolTypeList = require("../../db/school_types"); | ||
const faker = require("faker/locale/pl"); | ||
|
||
const schoolTypeData = (props = {}) => { | ||
const schoolTypeList = [ | ||
"przedszkole", | ||
"szkoła podstawowa", | ||
"szkoła zawodowa", | ||
"liceum ogólnokształcące" | ||
]; | ||
|
||
const getSchoolType = array => { | ||
const randomArrayItemNumber = Math.floor(Math.random() * array.length); | ||
const school_type = schoolTypeList[randomArrayItemNumber]; | ||
return school_type; | ||
}; | ||
|
||
return { schoolType: props || getSchoolType(schoolTypeList) }; | ||
const schoolTypeData = () => { | ||
return faker.random.arrayElement(schoolTypeList); | ||
}; | ||
|
||
const schoolTypeFixture = async (props = {}) => | ||
await SchoolType.create(schoolTypeData(props)); | ||
const schoolTypeFixture = async name => | ||
await SchoolType.create({ name: name || schoolTypeData() }); | ||
|
||
module.exports = schoolTypeFixture; | ||
module.exports.schoolTypeData = schoolTypeData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { createSchoolType } = require("../../db/api"); | ||
const schoolTypeList = require("../../db/school_types"); | ||
|
||
const insertSchoolTypes = schoolTypeList => { | ||
schoolTypeList.map(schoolType => createSchoolType(schoolType)); | ||
}; | ||
|
||
insertSchoolTypes(schoolTypeList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { createSchool } = require("../../db/api"); | ||
const { schoolData } = require("../factories/schoolFactory"); | ||
|
||
const insertSchool = () => { | ||
Array(10) | ||
.fill(0) | ||
.forEach(() => createSchool(schoolData())); | ||
}; | ||
|
||
insertSchool(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { sequelize } = require("../../db/db_config"); | ||
const schoolFactory = require("../factories/schoolFactory"); | ||
const truncate = require("../truncate"); | ||
const { School } = require("../../db/models"); | ||
|
||
describe("School model", () => { | ||
beforeEach(async () => { | ||
await truncate(School); | ||
}); | ||
|
||
afterEach(async () => { | ||
await truncate(School); | ||
}); | ||
|
||
it("should be created", async () => { | ||
const school = await sequelize | ||
.sync({ force: true }) | ||
.then(() => schoolFactory({ name: "TEST" })); | ||
|
||
expect(school).toBeTruthy(); | ||
expect(school.dataValues.name).toBe("TEST"); | ||
}); | ||
}); |
8 changes: 5 additions & 3 deletions
8
src/test/models/test.js → src/test/models/test_school_type_model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
const { sequelize } = require("../../db/db_config"); | ||
const schoolTypeFactory = require("../factories/schoolTypeFactory"); | ||
const truncate = require("../truncate"); | ||
const { SchoolType } = require("../../db/models"); | ||
|
||
describe("SchoolType model", () => { | ||
beforeEach(async () => { | ||
await truncate(); | ||
await truncate(SchoolType); | ||
}); | ||
|
||
afterEach(async () => { | ||
await truncate(); | ||
await truncate(SchoolType); | ||
}); | ||
|
||
it("should be created", async () => { | ||
const schoolType = await sequelize | ||
.sync({ force: true }) | ||
.then(() => schoolTypeFactory("mock school type")); | ||
|
||
expect(schoolType).toBeTruthy(); | ||
expect(schoolType.dataValues.schoolType).toBe("mock school type"); | ||
expect(schoolType.dataValues.name).toBe("mock school type"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const SchoolType = require("../db/models"); | ||
|
||
module.exports = async function truncate() { | ||
SchoolType.destroy({ where: {}, force: true }); | ||
module.exports = async function truncate(model) { | ||
model.destroy({ where: {}, force: true }); | ||
}; |