Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
test: added lastest test
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlacorrona committed Apr 23, 2019
1 parent 90c936d commit ad22908
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Chat {
//Save current sentMessages.
this.sentMessages = [];
let userID = this.user.id.replace("/profile/card#me", "").replace("https://", "");
console.log(" ** this.messages.length: " + this.messages.length);
for(var i = 0; i < this.messages.length; i++) {
if(this.messages[i].user === userID) {
if(this.messages[i].type==undefined){
Expand All @@ -78,7 +79,6 @@ class Chat {
//Saving to array current message
this.sentMessages.push(message);
this.messages.push(message);
console.log("** Count of messages after push:" + this.messages.length);
await chatManager.writeOwnPOD(this.user.id, this.partner.id, this.sentMessages);
return chatManager.writeInbox(this.partner, message.user);
}
Expand Down
38 changes: 38 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,42 @@ describe('Model tests', () => {
expect(instance.timestamp).toBeDefined();
});
});
describe('Message file', () => {
let instance;
let user, target;
beforeAll(() => {
user = new Person("https://paco.solid.community/profile/card#me", "Paco", "https://paco.solid.community/inbox")
target = new Person("https://carmen.solid.community/profile/card#me", "Carmen", "https://carmen.solid.community/inbox")
instance = new Message(user, target, "http://example.org/file.pdf", "file");
}),
it('Message should be created', () => {
expect(instance).toBeInstanceOf(Message)
}),
it('Attributes should match', () => {
expect(instance.user).toBe(user);
expect(instance.partner).toBe(target);
expect(instance.content).toBe("http://example.org/file.pdf");
expect(instance.type).toBe("file");
expect(instance.timestamp).toBeDefined();
});
});
describe('Message image', () => {
let instance;
let user, target;
beforeAll(() => {
user = new Person("https://paco.solid.community/profile/card#me", "Paco", "https://paco.solid.community/inbox")
target = new Person("https://carmen.solid.community/profile/card#me", "Carmen", "https://carmen.solid.community/inbox")
instance = new Message(user, target, "http://example.org/image.jpg", "image");
}),
it('Message should be created', () => {
expect(instance).toBeInstanceOf(Message)
}),
it('Attributes should match', () => {
expect(instance.user).toBe(user);
expect(instance.partner).toBe(target);
expect(instance.content).toBe("http://example.org/image.jpg");
expect(instance.type).toBe("image");
expect(instance.timestamp).toBeDefined();
});
});
});

0 comments on commit ad22908

Please sign in to comment.