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

Commit

Permalink
Check right friend story implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
uo258510 committed Apr 2, 2019
1 parent d318720 commit 0b425f1
Show file tree
Hide file tree
Showing 8 changed files with 4,174 additions and 85 deletions.
13 changes: 13 additions & 0 deletions acceptance-tests/features/friend_chatting.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: Can I send a message to a friend?
I want to know if i'm chatting with the right friend

Scenario Outline: Could the user check if he is chatting with the right friend
Given I'm using the chat app
When I want to start chatting with my friend "<friend>"
Then "<friend>" is the right person to send the message

Examples:
| friend |
| pruebaes5b |
| martinreycristina |
| srcharlystar |
13 changes: 0 additions & 13 deletions acceptance-tests/features/is_it_friday_yet.feature

This file was deleted.

9 changes: 2 additions & 7 deletions acceptance-tests/features/recieve_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ Feature: Can I recieve a message from a friend?

Scenario Outline: Could the user recieve a message from a friend
Given I'm using the chat app
When I'm chatting with "martinreycristina"
Then I recieve a message "Hi!" from my friend "martinreycristina"

Examples:
| friend | me |
| Send "Hi" | I can read "Hi" |
| Send "How are you?" | I can read "How are you" |
When I'm chatting with "pruebaes5b"
Then I recieve a message "Hi!" from my friend "pruebaes5b"
10 changes: 5 additions & 5 deletions acceptance-tests/features/send_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Feature: Can I send a message to a friend?
I want to know if I can send a message to a contact

Scenario Outline: Could the user send a message to a friend
Given I'm using the chat
Given I'm using the chat app
When I send a message "<message>" to a friend
Then My friend gets the message "<message>"

Examples:
| sender | reciever |
| Hi | Hello |
| How are you? | Fine thanks and you? |
| Fine too | Cool |
| message | friend |
| hi | pruebaes5b |
| how are you? | martinreycristina |
| good thanks | srcharlystar |
87 changes: 28 additions & 59 deletions acceptance-tests/features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,47 @@ const assert = require('assert');
const { Given, When, Then } = require('cucumber');
const chatManager1 = require("../../../src/chat/scripts/chatManager.js");
const chatManager2 = require("../../../src/chat/scripts/chatManager.js");
const fc = require("solid-file-client"); // <<<<<--------------------------------
const OK = 1; // <<<<<--------------------------------

function isItFriday(today) {
if (today === "Friday") {
return "TGIF";
} else {
return "Nope";
}
}

Given('today is {string}', function (givenDay) {
this.today = givenDay;
});

When('I ask whether it\'s Friday yet', function () {
this.actualAnswer = isItFriday(this.today);
});

Then('I should be told {string}', function (expectedAnswer) {
assert.equal(this.actualAnswer, expectedAnswer);
});

Given('I\'m using the chat', function() {
chatManager1.INFO.user="jandrolaviana";
chatManager1.INFO.receiver="pruebaes5b";
// SEND MESSAGE
Given('I\'m using the chat app', function() {
chatManager1.INFO.user = "jandrolaviana"; // ME
chatManager1.INFO.receiver = "pruebaes5b"; // MY FRIEND
chatManager1.MESSAGES.userMSG = ["Hey my friend", "Good thanks"];
chatManager1.MESSAGES.friendMSG = ["Hi!", "How are you?"];
});

When('I send a message {string} to a friend', async function(message) {
chatManager1.sendMessage = function() { return message; }
this.reply = await chatManager1.sendMessage(message);
When('I send a message {string} to a friend', function(message) {
chatManager1.sendMessage = function() { return true; }
this.reply = chatManager1.sendMessage(message);
});

Then('My friend gets the message {string}', function(message) {
assert.equal(this.reply, message);
});

Given('I\'m using the chat app', function() {
chatManager1.INFO.user="jandrolaviana"; // ME
chatManager1.INFO.receiver="pruebaes5b"; // MY FRIEND
chatManager1.MESSAGES.userMSG=["Hey my friend", "Good thanks"];
chatManager1.MESSAGES.friendMSG=["Hi!", "How are you?"];

chatManager2.INFO.user="jandrolaviana"; // ME
chatManager2.INFO.receiver="martinreycristina"; // MY FRIEND
chatManager2.MESSAGES.userMSG=["Hey Cristina", "Good thanks"];
chatManager2.MESSAGES.friendMSG=["Hi!", "How are you?"];
assert.equal(this.reply, true);
});

// RECEIVE MESSAGE
When('I\'m chatting with {string}', async function(friendName) {
var ok = false;
if(chatManager1.INFO.receiver === friendName)
ok = true;
else if(chatManager2.INFO.receiver === friendName)
ok = true;
assert.equal(ok, true);
assert.equal(chatManager1.INFO.receiver === friendName, true);
});

Then('I recieve a message {string} from my friend {string}', function(message, friendName) {
var ok = containsMessageAndFriend(chatManager1, message, friendName);
if(ok === true)
assert.equal(ok, true);
else {
ok = containsMessageAndFriend(chatManager2, message, friendName);
assert.equal(ok, true);
}
assert.equal(containsMessageAndFriend(chatManager1, message, friendName), true);
});

function containsMessageAndFriend(cm, message, friendName) {
var i;
for(i=0; i<cm.MESSAGES.friendMSG.length; i++)
if(cm.MESSAGES.friendMSG[i] === message && cm.INFO.receiver === friendName)
return true;
return false;
var i;
for (i = 0; i < cm.MESSAGES.friendMSG.length; i++)
if (cm.MESSAGES.friendMSG[i] === message && cm.INFO.receiver === friendName)
return true;
return false;
}

// CHECK RIGHT FRIEND
When('I want to start chatting with my friend {string}', async function(friendName) {
chatManager1.INFO.receiver = friendName;
chatManager1.getReceiver = function() { return chatManager1.INFO.receiver; }
});

Then('{string} is the right person to send the message', function(friendName) {
assert.equal(chatManager1.getReceiver(), friendName);
});
2 changes: 1 addition & 1 deletion src/chat/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/chat/scripts/chatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function sendMessage(text){
if(ToLog)
console.log("Writting message: "+text);
await writeMessage(folder+"/"+(new Date().getTime()), text);
return true;
}

//TO-DO
Expand Down
Loading

0 comments on commit 0b425f1

Please sign in to comment.