-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from andela/ft-text-highlight-166240846
#166240846 highlight text
- Loading branch information
Showing
10 changed files
with
182 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Highlights', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
startIndex: { | ||
type: Sequelize.INTEGER | ||
}, | ||
lastIndex: { | ||
type: Sequelize.INTEGER | ||
}, | ||
text: { | ||
type: Sequelize.STRING | ||
}, | ||
comment: { | ||
type: Sequelize.STRING | ||
}, | ||
articleSlug: { | ||
type: Sequelize.STRING, | ||
references: { model: 'Articles', key: 'slug' } | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
references: { model: 'Users', key: 'id'} | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Highlights'); | ||
} | ||
}; |
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,21 @@ | ||
export default (sequelize, DataTypes) => { | ||
const Highlight = sequelize.define('Highlight', { | ||
startIndex: DataTypes.INTEGER, | ||
lastIndex: DataTypes.INTEGER, | ||
text: DataTypes.STRING, | ||
comment: DataTypes.STRING, | ||
articleSlug: DataTypes.STRING, | ||
userId: DataTypes.INTEGER | ||
}, {}); | ||
Highlight.associate = (models) => { | ||
Highlight.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
onDelete: 'CASCADE' | ||
}); | ||
Highlight.belongsTo(models.Article, { | ||
foreignKey: 'articleSlug', | ||
onDelete: 'CASCADE' | ||
}); | ||
}; | ||
return Highlight; | ||
}; |
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 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 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,55 @@ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
|
||
import server from '../src/index'; | ||
import statusCodes from '../src/helpers/constants/status.codes'; | ||
import signup from '../src/helpers/tests/signup'; | ||
import errorMessage from '../src/helpers/constants/error.messages'; | ||
|
||
|
||
chai.use(chaiHttp); | ||
chai.should(); | ||
|
||
const { CREATED, BAD_REQUEST } = statusCodes; | ||
const highlitedData = { | ||
startIndex: 3, | ||
lastIndex: 8, | ||
text: 'text g', | ||
comment: 'is correct' | ||
}; | ||
|
||
const token = signup(); | ||
describe('Highlight', () => { | ||
it('should highlight a text', (done) => { | ||
chai | ||
.request(server) | ||
.post('/api/articles/How-to-create-sequalize-seeds/highlight') | ||
.set('Authorization', token) | ||
.send({ | ||
...highlitedData | ||
}) | ||
.end((err, res) => { | ||
res.should.have.status(CREATED); | ||
res.body.highlighted.should.include(highlitedData); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('Validation', () => { | ||
it('the text length should match the indexes', (done) => { | ||
highlitedData.startIndex = 2; | ||
chai | ||
.request(server) | ||
.post('/api/articles/How-to-create-sequalize-seeds/highlight') | ||
.set('Authorization', token) | ||
.send({ | ||
...highlitedData | ||
}) | ||
.end((err, res) => { | ||
res.should.have.status(BAD_REQUEST); | ||
res.body.errors.should.have.property('text', errorMessage.textMatch); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |