Skip to content

Instantly share code, notes, and snippets.

@gatarelib
Created August 14, 2019 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatarelib/13dec57917b1ed5dff9da6f34a1f960e to your computer and use it in GitHub Desktop.
Save gatarelib/13dec57917b1ed5dff9da6f34a1f960e to your computer and use it in GitHub Desktop.
Andela-assessment
class User {
constructor(name) {
this._name = name;
this._loggedIn = false;
this._lastLoggedInAt = null;
}
isLoggedIn() {
return this._loggedIn;
}
getLastLoggedInAt() {
return this._lastLoggedInAt;
}
logIn() {
this._lastLoggedInAt = new Date();
this._loggedIn = true;
}
logOut() {
this._loggedIn = false
}
getName() {
return this._name;
}
setName(name) {
this._name = name;
}
canEdit(comment) {
if(comment._author._name === this._name) {
return true;
}
return false;
}
canDelete(comment) {
return false;
}
}
class Moderator extends User {
constructor(name) {
super(name);
}
canDelete(comment) {
return true;
}
}
class Admin extends Moderator {
constructor(name) {
super(name)
}
canEdit(comment) {
return true;
}
}
class Comment {
constructor(author = null, message, repliedTo = null) {
this._createdAt = new Date();
this._message = message;
this._repliedTo = repliedTo;
this._author = author;
}
getMessage() {
return this._message;
}
setMessage(message) {
this._message = message;
}
getCreatedAt() {
return this._createdAt;
}
getAuthor() {
return this._author;
}
getRepliedTo() {
return this._repliedTo;
}
toString() {
if(this._repliedTo === null) {
return this._message + " by " + this._author._name
}
return this._message + " by " + this._author._name + " (replied to " +
this._repliedTo._author._name + ")"
}
}
var should = require('should');
describe('OOP Tests', function() {
it('example tests', function() {
var user = new User("User 1");
user.getName().should.eql('User 1', 'User name is set correctly');
var mod = new Moderator("Moderator");
mod.should.be.an.instanceof(User, 'Moderator is a User');
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment