Skip to content

Commit

Permalink
Change wording of emails #35
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Feb 4, 2016
1 parent 80a6d14 commit 94130ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 57 deletions.
51 changes: 31 additions & 20 deletions application/libraries/Auto_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ private function findLastBatchDate(){
private function showSentEmails($emails, $title){

echo "<h2> ".$title." </h2>";

foreach ($emails as $email) {
echo 'TO ' . $this->CI->user->find_by('userId', $email['userId'])->email;
echo '\n'; var_dump($email['mandrill']); echo '\n';
Expand Down Expand Up @@ -397,8 +396,13 @@ private function inactiveUser(&$queuedEmail) {
if ($inactiveUsers !== FALSE) {
foreach ($inactiveUsers as $user) {

$emailcontent = $this->CI->load->view('email/generic',
comebackContent($user->firstname), true);
$emailcontent = $this->CI->load->view(
'email/generic',
comebackContent(
$user->firstname,
$this->CI->measure->getMeasuresByUser($user->userId)
), true
);

$this->addEmailToQueue(
$queuedEmail,
Expand Down Expand Up @@ -475,40 +479,43 @@ private function userWithWatchWithoutMeasure(&$queuedEmail) {

$userWithWatchWithoutMeasure = $this->CI
->watch
->select('watch.watchId, watch.brand, watch.name as watchName,
user.name, user.firstname, email')
->select('user.userId, watch.watchId, watch.brand, watch.name as watchName,
user.name as lastname, user.firstname, email')
->join('user', 'watch.userId = user.userId')
->where('(select count(1) from measure where watch.watchId = measure.watchId) = ', 0)
->where('(select count(1) from watch where watch.userId = user.userId) = ', 1)
->where('creationDate < ', $this->getBatchUpperBound($this->day))
->where('creationDate > ', $this->getBatchLowerBound($this->day))
->as_array()
->find_all();

if ($userWithWatchWithoutMeasure !== FALSE) {

$this->CI->__->groupBy($userWithWatchWithoutMeasure, 'email');
$userWithWatchWithoutMeasure = $this->CI->__->groupBy($userWithWatchWithoutMeasure, 'email');

foreach ($userWithWatchWithoutMeasure as $user) {

$user = (object) $user;

$emailcontent = $this->CI->load->view('email/generic',
makeFirstMeasureContent($user->firstname,
$user->brand . ' ' . $user->watchName), true);
$emailcontent = $this->CI->load->view(
'email/generic',
makeFirstMeasureContent(
$user->firstname,
$user,
$this->CI->measure->getMeasuresByUser($user[0]['userId'])
),
true
);

$this->addEmailToQueue(
$queuedEmail,
$user->watchId,
$user[0]['watchId'],
$this->START_FIRST_MEASURE,
$this->time,
'watchId',
$emailcontent,
$this->sendMandrillEmail(
'Let’s start measuring! ⌚',
$emailcontent,
$user->name.' '.$user->firstname,
$user->email,
$user[0]['lastname'].' '.$user[0]['firstname'],
$user[0]['email'],
'make_first_measure_email',
$this->sendAtString($this->time)
)
Expand Down Expand Up @@ -549,11 +556,15 @@ private function userWithOneCompleteMeasureAndOneWatch(&$queuedEmail) {
->select('brand, name')
->find_by('userid', $user->userId);

$emailcontent = $this->CI->load->view('email/generic',
addSecondWatchContent($user->firstname,
$watch->brand . " " .
$watch->name)
, true);
$emailcontent = $this->CI->load->view(
'email/generic',
addSecondWatchContent(
$user->firstname,
$watch->brand . " " . $watch->name,
$this->CI->measure->getMeasuresByUser($user->userId)
),
true
);

$this->addEmailToQueue(
$queuedEmail,
Expand Down
2 changes: 1 addition & 1 deletion application/libraries/Mandrill.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Mandrill {
);

public function __construct() {
$apikey = false;
$apikey = "vZMIOmGRBA1KWow4yfRcfQ";

if (!$apikey) {$apikey = getenv('MANDRILL_APIKEY');
}
Expand Down
54 changes: 18 additions & 36 deletions application/tests/libraries/Auto_email_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,41 +226,28 @@ public function test_AccuracyAndAddFirstWatch(){
//1 day later and 1 sec later
// Should have 5 add first and 1 check
$emails = $this->email->cronCheck(24*60*61);

$addWatchContent = file_get_contents("emails/add_watch.html",
FILE_USE_INCLUDE_PATH);
$checkAccuracyContent = file_get_contents("emails/check_accuracy.html",
FILE_USE_INCLUDE_PATH);

$this->assertEquals(sizeof($emails['users']), 5);

$this->assertEquals($emails['users'][0]['userId'], self::$users['ernest']->userId);
$this->assertEquals($emails['users'][0]['emailType'], $this->email->ADD_FIRST_WATCH);
$this->assertEquals($emails['users'][0]['content'], $addWatchContent);

$this->assertEquals($emails['users'][1]['userId'], self::$users['anatole']->userId);
$this->assertEquals($emails['users'][1]['emailType'], $this->email->ADD_FIRST_WATCH);
$this->assertEquals($emails['users'][1]['content'], $addWatchContent);

$this->assertEquals($emails['users'][2]['userId'], self::$users['phillibert']->userId);
$this->assertEquals($emails['users'][2]['emailType'], $this->email->ADD_FIRST_WATCH);
$this->assertEquals($emails['users'][2]['content'], $addWatchContent);

$this->assertEquals($emails['users'][3]['userId'], self::$users['hippolyte']->userId);
$this->assertEquals($emails['users'][3]['emailType'], $this->email->ADD_FIRST_WATCH);
$this->assertEquals($emails['users'][3]['content'], $addWatchContent);

$this->assertEquals($emails['users'][4]['userId'], self::$users['raymond']->userId);
$this->assertEquals($emails['users'][4]['emailType'], $this->email->ADD_FIRST_WATCH);
$this->assertEquals($emails['users'][4]['content'], $addWatchContent);

$this->assertEquals(sizeof($emails['watches']), 0);

$this->assertEquals(sizeof($emails['measures']), 1);
$this->assertEquals($emails['measures'][0]['measureId'], self::$baseMeasureId);
$this->assertEquals($emails['measures'][0]['emailType'], $this->email->CHECK_ACCURACY);
$this->assertEquals($emails['measures'][0]['content'], $checkAccuracyContent);

}

/**
Expand All @@ -274,17 +261,13 @@ public function test_AccuracyOneWeek(){
// Should have 1 CHECK_ACCURACY_1_WEEK
$emails = $this->email->cronCheck(24*8*60*61);

$checkAccuracy1wContent = file_get_contents("emails/check_accuracy_1w.html",
FILE_USE_INCLUDE_PATH);

$this->assertEquals(sizeof($emails['users']), 0);
$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['measures']), 1);

$this->assertEquals($emails['measures'][0]['measureId'], self::$baseMeasureId);
$this->assertEquals($emails['measures'][0]['emailType'],
$this->email->CHECK_ACCURACY_1_WEEK);
$this->assertEquals($emails['measures'][0]['content'], $checkAccuracy1wContent);
}

/**
Expand Down Expand Up @@ -317,9 +300,6 @@ public function test_addSecondWatch(){
//2 days later
$emails = $this->email->cronCheck(24*10*61*60);

$addSecondWatch = file_get_contents("emails/add_second_watch.html",
FILE_USE_INCLUDE_PATH);

$this->assertEquals(sizeof($emails['users']), 1);

$this->assertEquals($emails['users'][0]['userId'],
Expand All @@ -328,8 +308,6 @@ public function test_addSecondWatch(){
$this->assertEquals($emails['users'][0]['emailType'],
$this->email->ADD_SECOND_WATCH);

$this->assertEquals($emails['users'][0]['content'], $addSecondWatch);

$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['measures']), 0);

Expand All @@ -352,18 +330,13 @@ public function test_startANewMeasure(){
//The accuracy measure was at time()+(24*8*60*60)
$emails = $this->email->cronCheck(24*39*60*60);

$startNewMeasureContent = file_get_contents("emails/start_new_measure.html",
FILE_USE_INCLUDE_PATH);

$this->assertEquals(sizeof($emails['watches']), 1);

$this->assertEquals($emails['watches'][0]['watchId'],
self::$watchId);

$this->assertEquals($emails['watches'][0]['emailType'],
$this->email->START_NEW_MEASURE);
$this->assertEquals($emails['watches'][0]['content'],
$startNewMeasureContent);

$this->assertEquals(sizeof($emails['users']), 0);
$this->assertEquals(sizeof($emails['measures']), 0);
Expand All @@ -385,16 +358,12 @@ public function test_comback(){
//Last Login was at time()
$emails = $this->email->cronCheck(100*25*60*60);

$comebackContent = file_get_contents("emails/comeback.html",
FILE_USE_INCLUDE_PATH);

$this->assertEquals(sizeof($emails['users']), 6);
$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['measures']), 0);

$this->assertEquals($emails['users'][0]['userId'], self::$users['nestor']->userId);
$this->assertEquals($emails['users'][0]['emailType'], $this->email->COMEBACK);
$this->assertEquals($emails['users'][0]['content'], $comebackContent);

$this->assertEquals($emails['users'][1]['userId'], self::$users['ernest']->userId);
$this->assertEquals($emails['users'][1]['emailType'], $this->email->COMEBACK);
Expand Down Expand Up @@ -426,6 +395,7 @@ public function test_comback(){
public function test_addFirstMeasure(){

$this->watchModel->delete_where(array("watchId >=" => "0"));
$this->measureModel->delete_where(array("id >=" => "0"));

$data = array(
'userId' => self::$users['nestor']->userId,
Expand All @@ -436,6 +406,15 @@ public function test_addFirstMeasure(){
'caliber' => 'caliber',
'creationDate' => time() + 101*25*60*60);

$data = array(
'userId' => self::$users['nestor']->userId,
'brand' => 'rolex',
'name' => 'marolex2',
'yearOfBuy' => '2000',
'serial' => '0000-0000',
'caliber' => 'caliber',
'creationDate' => time() + 101*25*60*60);

self::$watchId = $this->watchModel->insert($data);

//The watch is added at time() + 24*39*61*60
Expand All @@ -447,12 +426,15 @@ public function test_addFirstMeasure(){
$this->assertEquals(sizeof($emails['measures']), 0);


//Check that the email is sent only once
$emails = $this->email->cronCheck(24*1*62*60);
//test en ajoutant une autre montre


$this->assertEquals(sizeof($emails['users']), 0);
$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['measures']), 0);
//Check that the email is sent only once
$emails = $this->email->cronCheck(24*1*62*60);

$this->assertEquals(sizeof($emails['users']), 0);
$this->assertEquals(sizeof($emails['watches']), 0);
$this->assertEquals(sizeof($emails['measures']), 0);
}

public static function tearDownAfterClass() {
Expand Down

0 comments on commit 94130ca

Please sign in to comment.