{"action":"created","comment":{"url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/comments/68500484","id":68500484,"diff_hunk":"@@ -0,0 +1,134 @@\n+import UIKit\n+import XCTest\n+@testable import malaria_ios\n+\n+class TestMedicineStockManager: XCTestCase {\n+  \n+  let secondsTillYesterday: Double = -86400.0\n+  let twoDaysAgo: Double = -86400.0 * 2\n+  let secondTillTomorrow: Double = 86400.0\n+  \n+  var m: MedicineManager!\n+  var msm: MedicineStockManager!\n+  \n+  let currentPill = Medicine.Pill.Malarone\n+  \n+  var currentContext: NSManagedObjectContext!\n+  \n+  override func setUp() {\n+    super.setUp()\n+    \n+    currentContext = CoreDataHelper.sharedInstance.createBackgroundContext()\n+    m = MedicineManager(context: currentContext)\n+    m.registerNewMedicine(currentPill.name(), interval: currentPill.interval())\n+    m.setCurrentPill(currentPill.name())\n+  \n+    msm = MedicineStockManager(medicine: m.getCurrentMedicine()!)\n+  }\n+  \n+  override func tearDown() {\n+    super.tearDown()\n+    m.clearCoreData()\n+  }\n+  \n+  // Checks if Core Date successfully updates remaining pills for medicine\n+  func testUpdateStock() {\n+    guard let medicine = m.getCurrentMedicine() else {\n+      XCTFail(\"Fail initializing:\")\n+      return\n+    }\n+    \n+    medicine.remainingMedicine = 1\n+    \n+    msm.updateStock(true)\n+    XCTAssertEqual(medicine.remainingMedicine, 0)\n+\n+    msm.updateStock(false)\n+    XCTAssertEqual(medicine.remainingMedicine, 1)\n+  }\n+  \n+  func testUserHasEnoughPillsToPressYes() {\n+    guard let medicine = m.getCurrentMedicine() else {\n+      XCTFail(\"Fail initializing:\")\n+      return\n+    }\n+    \n+    medicine.remainingMedicine = 0\n+    \n+    XCTAssertFalse(msm.addRegistry(NSDate(), tookMedicine: true))\n+\n+    medicine.remainingMedicine = 1\n+    \n+    XCTAssertTrue(msm.addRegistry(NSDate(), tookMedicine: true))\n+  }\n+  \n+  // Makes sure the updateStock method is not called for a date before the refill date\n+  // because the reminder shouldn't care about past values in order to update the current stock\n+  func testUpdateStockWhenDateBeforeRefill() {\n+    guard let medicine = m.getCurrentMedicine() else {\n+      XCTFail(\"Fail initializing:\")\n+      return\n+    }\n+    \n+    msm.addRegistry(NSDate().dateByAddingTimeInterval(secondsTillYesterday), tookMedicine: true)\n+    \n+    XCTAssertFalse(medicine.remainingMedicine == 1)\n+    XCTAssertTrue(medicine.remainingMedicine == 0)","path":"malaria-iosTests/TestMedicineStockManager.swift","position":76,"original_position":76,"commit_id":"7f98ff35f0d9a96ee0b4fb7e9d5e1ba8f40cc95e","original_commit_id":"7f98ff35f0d9a96ee0b4fb7e9d5e1ba8f40cc95e","user":{"login":"bphenriques","id":4727729,"avatar_url":"https://avatars.githubusercontent.com/u/4727729?v=3","gravatar_id":"","url":"https://api.github.com/users/bphenriques","html_url":"https://github.com/bphenriques","followers_url":"https://api.github.com/users/bphenriques/followers","following_url":"https://api.github.com/users/bphenriques/following{/other_user}","gists_url":"https://api.github.com/users/bphenriques/gists{/gist_id}","starred_url":"https://api.github.com/users/bphenriques/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bphenriques/subscriptions","organizations_url":"https://api.github.com/users/bphenriques/orgs","repos_url":"https://api.github.com/users/bphenriques/repos","events_url":"https://api.github.com/users/bphenriques/events{/privacy}","received_events_url":"https://api.github.com/users/bphenriques/received_events","type":"User","site_admin":false},"body":"Redudant Assert (same field). Keep one of them.","created_at":"2016-06-26T09:53:50Z","updated_at":"2016-06-26T09:53:50Z","html_url":"https://github.com/systers/malaria-app-ios/pull/52#discussion_r68500484","pull_request_url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52","_links":{"self":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/comments/68500484"},"html":{"href":"https://github.com/systers/malaria-app-ios/pull/52#discussion_r68500484"},"pull_request":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52"}}},"pull_request":{"url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52","id":75176127,"html_url":"https://github.com/systers/malaria-app-ios/pull/52","diff_url":"https://github.com/systers/malaria-app-ios/pull/52.diff","patch_url":"https://github.com/systers/malaria-app-ios/pull/52.patch","issue_url":"https://api.github.com/repos/systers/malaria-app-ios/issues/52","number":52,"state":"open","locked":false,"title":"Add remaining pills mechanism","user":{"login":"teo029","id":7328298,"avatar_url":"https://avatars.githubusercontent.com/u/7328298?v=3","gravatar_id":"","url":"https://api.github.com/users/teo029","html_url":"https://github.com/teo029","followers_url":"https://api.github.com/users/teo029/followers","following_url":"https://api.github.com/users/teo029/following{/other_user}","gists_url":"https://api.github.com/users/teo029/gists{/gist_id}","starred_url":"https://api.github.com/users/teo029/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teo029/subscriptions","organizations_url":"https://api.github.com/users/teo029/orgs","repos_url":"https://api.github.com/users/teo029/repos","events_url":"https://api.github.com/users/teo029/events{/privacy}","received_events_url":"https://api.github.com/users/teo029/received_events","type":"User","site_admin":false},"body":"**Summary**: Adds a mechanism through which the users will have to keep track of their medicine in order to use the application and will also help them set reminders for when they remain out of medicine.\r\n\r\n**User Profile View Controller**\r\n\r\nA new class that, for the moment, implements only the pill taking mechanism. It allows the user to set a _Reminder Time_ for a specific interval of not having enough pills.\r\n\r\n**Example**: I want to be reminded when I lack pills for more than **4 days**.\r\n\r\nMoreover, this class is the one responsible with letting the user change his current medicine stock. The user will type in their current available pills and the stock will automatically update (and also the rest of the app's screens).\r\n\r\nA label will be presented on the bottom, stating for how long the user still has pills. **If the value is lower than the value he set a reminder to track, the label will turn red and a local notification will appear.**.\r\n\r\n**Use-case**:\r\n\r\nThe volunteers sets their current medicine stock in the _User Profile_ tab and can start selecting if they did or didn't take their pill from the home screen or from the calendar. \r\n\r\nIn the calendar, the user still have the possibility to change decisions made for dates in the past (change _Take_ pill into _Didn't take_), **without the need to posses any medicine**, because decisions before the _Refill Date_ (the last date he modified his remaining medicine stock) won't affect the current stock.\r\n\r\nWhen the user changes a decision made **after the refill date**, she will either take her medicine back (if setting _I didn't took my pill_ when she said she took) or the medicine stock will be decremented when confirming pill taking.\r\n\r\n**Changes**\r\n\r\n- _WidgetHandler_ logic was modified to support this mechanism.\r\n- A MedicineStockManager was created in order to add the logic behind tracking if the user has enough pills and when to decrement / increment stock.\r\n- All classes now call the MedicineStockManager's _addRegistry()_ instead of the RegistriesManager one, in order for the manager to confirm if the user can add a registry at that moment (if only he has enough pills).\r\n- A _UserProfile_ class was created where, for the moment, only the pill taking UI was implemented.\r\n- Adds new _Unit tests_ for the MedicineStockManager.\r\n- A _MedicineNotificationsHelper_ was added in order to add a new set of custom notifications when the user lacks enough pills (based on his reminder).\r\n- The _NotificationManager_ now archives the notifications persistently, in order to remove correctly when needed.","created_at":"2016-06-24T21:26:34Z","updated_at":"2016-06-26T09:53:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d956f9a752658cf62b41c1b0363c2d04104bbc6e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52/commits","review_comments_url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52/comments","review_comment_url":"https://api.github.com/repos/systers/malaria-app-ios/pulls/comments{/number}","comments_url":"https://api.github.com/repos/systers/malaria-app-ios/issues/52/comments","statuses_url":"https://api.github.com/repos/systers/malaria-app-ios/statuses/7f98ff35f0d9a96ee0b4fb7e9d5e1ba8f40cc95e","head":{"label":"teo029:remaining-pills","ref":"remaining-pills","sha":"7f98ff35f0d9a96ee0b4fb7e9d5e1ba8f40cc95e","user":{"login":"teo029","id":7328298,"avatar_url":"https://avatars.githubusercontent.com/u/7328298?v=3","gravatar_id":"","url":"https://api.github.com/users/teo029","html_url":"https://github.com/teo029","followers_url":"https://api.github.com/users/teo029/followers","following_url":"https://api.github.com/users/teo029/following{/other_user}","gists_url":"https://api.github.com/users/teo029/gists{/gist_id}","starred_url":"https://api.github.com/users/teo029/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teo029/subscriptions","organizations_url":"https://api.github.com/users/teo029/orgs","repos_url":"https://api.github.com/users/teo029/repos","events_url":"https://api.github.com/users/teo029/events{/privacy}","received_events_url":"https://api.github.com/users/teo029/received_events","type":"User","site_admin":false},"repo":{"id":59411281,"name":"malaria-app-ios","full_name":"teo029/malaria-app-ios","owner":{"login":"teo029","id":7328298,"avatar_url":"https://avatars.githubusercontent.com/u/7328298?v=3","gravatar_id":"","url":"https://api.github.com/users/teo029","html_url":"https://github.com/teo029","followers_url":"https://api.github.com/users/teo029/followers","following_url":"https://api.github.com/users/teo029/following{/other_user}","gists_url":"https://api.github.com/users/teo029/gists{/gist_id}","starred_url":"https://api.github.com/users/teo029/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teo029/subscriptions","organizations_url":"https://api.github.com/users/teo029/orgs","repos_url":"https://api.github.com/users/teo029/repos","events_url":"https://api.github.com/users/teo029/events{/privacy}","received_events_url":"https://api.github.com/users/teo029/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/teo029/malaria-app-ios","description":"","fork":true,"url":"https://api.github.com/repos/teo029/malaria-app-ios","forks_url":"https://api.github.com/repos/teo029/malaria-app-ios/forks","keys_url":"https://api.github.com/repos/teo029/malaria-app-ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/teo029/malaria-app-ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/teo029/malaria-app-ios/teams","hooks_url":"https://api.github.com/repos/teo029/malaria-app-ios/hooks","issue_events_url":"https://api.github.com/repos/teo029/malaria-app-ios/issues/events{/number}","events_url":"https://api.github.com/repos/teo029/malaria-app-ios/events","assignees_url":"https://api.github.com/repos/teo029/malaria-app-ios/assignees{/user}","branches_url":"https://api.github.com/repos/teo029/malaria-app-ios/branches{/branch}","tags_url":"https://api.github.com/repos/teo029/malaria-app-ios/tags","blobs_url":"https://api.github.com/repos/teo029/malaria-app-ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/teo029/malaria-app-ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/teo029/malaria-app-ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/teo029/malaria-app-ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/teo029/malaria-app-ios/statuses/{sha}","languages_url":"https://api.github.com/repos/teo029/malaria-app-ios/languages","stargazers_url":"https://api.github.com/repos/teo029/malaria-app-ios/stargazers","contributors_url":"https://api.github.com/repos/teo029/malaria-app-ios/contributors","subscribers_url":"https://api.github.com/repos/teo029/malaria-app-ios/subscribers","subscription_url":"https://api.github.com/repos/teo029/malaria-app-ios/subscription","commits_url":"https://api.github.com/repos/teo029/malaria-app-ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/teo029/malaria-app-ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/teo029/malaria-app-ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/teo029/malaria-app-ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/teo029/malaria-app-ios/contents/{+path}","compare_url":"https://api.github.com/repos/teo029/malaria-app-ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/teo029/malaria-app-ios/merges","archive_url":"https://api.github.com/repos/teo029/malaria-app-ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/teo029/malaria-app-ios/downloads","issues_url":"https://api.github.com/repos/teo029/malaria-app-ios/issues{/number}","pulls_url":"https://api.github.com/repos/teo029/malaria-app-ios/pulls{/number}","milestones_url":"https://api.github.com/repos/teo029/malaria-app-ios/milestones{/number}","notifications_url":"https://api.github.com/repos/teo029/malaria-app-ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/teo029/malaria-app-ios/labels{/name}","releases_url":"https://api.github.com/repos/teo029/malaria-app-ios/releases{/id}","deployments_url":"https://api.github.com/repos/teo029/malaria-app-ios/deployments","created_at":"2016-05-22T12:33:06Z","updated_at":"2016-05-22T12:33:07Z","pushed_at":"2016-06-25T21:45:57Z","git_url":"git://github.com/teo029/malaria-app-ios.git","ssh_url":"git@github.com:teo029/malaria-app-ios.git","clone_url":"https://github.com/teo029/malaria-app-ios.git","svn_url":"https://github.com/teo029/malaria-app-ios","homepage":null,"size":81923,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"systers:develop","ref":"develop","sha":"8e23906d9cb6abae4b190ad5dd96fd2477e3e49a","user":{"login":"systers","id":6520415,"avatar_url":"https://avatars.githubusercontent.com/u/6520415?v=3","gravatar_id":"","url":"https://api.github.com/users/systers","html_url":"https://github.com/systers","followers_url":"https://api.github.com/users/systers/followers","following_url":"https://api.github.com/users/systers/following{/other_user}","gists_url":"https://api.github.com/users/systers/gists{/gist_id}","starred_url":"https://api.github.com/users/systers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systers/subscriptions","organizations_url":"https://api.github.com/users/systers/orgs","repos_url":"https://api.github.com/users/systers/repos","events_url":"https://api.github.com/users/systers/events{/privacy}","received_events_url":"https://api.github.com/users/systers/received_events","type":"Organization","site_admin":false},"repo":{"id":18889825,"name":"malaria-app-ios","full_name":"systers/malaria-app-ios","owner":{"login":"systers","id":6520415,"avatar_url":"https://avatars.githubusercontent.com/u/6520415?v=3","gravatar_id":"","url":"https://api.github.com/users/systers","html_url":"https://github.com/systers","followers_url":"https://api.github.com/users/systers/followers","following_url":"https://api.github.com/users/systers/following{/other_user}","gists_url":"https://api.github.com/users/systers/gists{/gist_id}","starred_url":"https://api.github.com/users/systers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systers/subscriptions","organizations_url":"https://api.github.com/users/systers/orgs","repos_url":"https://api.github.com/users/systers/repos","events_url":"https://api.github.com/users/systers/events{/privacy}","received_events_url":"https://api.github.com/users/systers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/systers/malaria-app-ios","description":"","fork":true,"url":"https://api.github.com/repos/systers/malaria-app-ios","forks_url":"https://api.github.com/repos/systers/malaria-app-ios/forks","keys_url":"https://api.github.com/repos/systers/malaria-app-ios/keys{/key_id}","collaborators_url":"https://api.github.com/repos/systers/malaria-app-ios/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/systers/malaria-app-ios/teams","hooks_url":"https://api.github.com/repos/systers/malaria-app-ios/hooks","issue_events_url":"https://api.github.com/repos/systers/malaria-app-ios/issues/events{/number}","events_url":"https://api.github.com/repos/systers/malaria-app-ios/events","assignees_url":"https://api.github.com/repos/systers/malaria-app-ios/assignees{/user}","branches_url":"https://api.github.com/repos/systers/malaria-app-ios/branches{/branch}","tags_url":"https://api.github.com/repos/systers/malaria-app-ios/tags","blobs_url":"https://api.github.com/repos/systers/malaria-app-ios/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/systers/malaria-app-ios/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/systers/malaria-app-ios/git/refs{/sha}","trees_url":"https://api.github.com/repos/systers/malaria-app-ios/git/trees{/sha}","statuses_url":"https://api.github.com/repos/systers/malaria-app-ios/statuses/{sha}","languages_url":"https://api.github.com/repos/systers/malaria-app-ios/languages","stargazers_url":"https://api.github.com/repos/systers/malaria-app-ios/stargazers","contributors_url":"https://api.github.com/repos/systers/malaria-app-ios/contributors","subscribers_url":"https://api.github.com/repos/systers/malaria-app-ios/subscribers","subscription_url":"https://api.github.com/repos/systers/malaria-app-ios/subscription","commits_url":"https://api.github.com/repos/systers/malaria-app-ios/commits{/sha}","git_commits_url":"https://api.github.com/repos/systers/malaria-app-ios/git/commits{/sha}","comments_url":"https://api.github.com/repos/systers/malaria-app-ios/comments{/number}","issue_comment_url":"https://api.github.com/repos/systers/malaria-app-ios/issues/comments{/number}","contents_url":"https://api.github.com/repos/systers/malaria-app-ios/contents/{+path}","compare_url":"https://api.github.com/repos/systers/malaria-app-ios/compare/{base}...{head}","merges_url":"https://api.github.com/repos/systers/malaria-app-ios/merges","archive_url":"https://api.github.com/repos/systers/malaria-app-ios/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/systers/malaria-app-ios/downloads","issues_url":"https://api.github.com/repos/systers/malaria-app-ios/issues{/number}","pulls_url":"https://api.github.com/repos/systers/malaria-app-ios/pulls{/number}","milestones_url":"https://api.github.com/repos/systers/malaria-app-ios/milestones{/number}","notifications_url":"https://api.github.com/repos/systers/malaria-app-ios/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/systers/malaria-app-ios/labels{/name}","releases_url":"https://api.github.com/repos/systers/malaria-app-ios/releases{/id}","deployments_url":"https://api.github.com/repos/systers/malaria-app-ios/deployments","created_at":"2014-04-17T18:54:01Z","updated_at":"2016-04-03T11:46:09Z","pushed_at":"2016-06-25T21:45:58Z","git_url":"git://github.com/systers/malaria-app-ios.git","ssh_url":"git@github.com:systers/malaria-app-ios.git","clone_url":"https://github.com/systers/malaria-app-ios.git","svn_url":"https://github.com/systers/malaria-app-ios","homepage":null,"size":90142,"stargazers_count":3,"watchers_count":3,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":14,"forks":17,"open_issues":14,"watchers":3,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52"},"html":{"href":"https://github.com/systers/malaria-app-ios/pull/52"},"issue":{"href":"https://api.github.com/repos/systers/malaria-app-ios/issues/52"},"comments":{"href":"https://api.github.com/repos/systers/malaria-app-ios/issues/52/comments"},"review_comments":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52/comments"},"review_comment":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/systers/malaria-app-ios/pulls/52/commits"},"statuses":{"href":"https://api.github.com/repos/systers/malaria-app-ios/statuses/7f98ff35f0d9a96ee0b4fb7e9d5e1ba8f40cc95e"}}}}
{"actor":{"display_login":"bphenriques"}}