Benjamin Ruddy
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # The Fortune Cookie Wars Episode 4: The Phantom Cookie (Sprint 4) ## Work Accomplished ### Front-end The front-end team continued to implement the remaining functionalities left from sprint 3. Gabi focused on eat cookie, past fortunes, and logout. She updated the html, ts, and css files respectively to get the form and function of each page working. Ben used his time to create a separate user profile page and also helped clean up some of the pages' UI design. On an individual basis, Gabi spent some time catching up to what Ben had learned last sprint regarding the Tour of Heroes tutorial and how that related to the way we planned to implement our sending and receiving fortunes from the database. Separately, Ben took the time to develop more end-to-end Cypress tests to confirm the security of the website navigation, ensuring that user pages and fortune sending/receiving was only possible if signed in. Finally, a change was made to separate out the user's profile into its own Angular component, as opposed to being displayed in the signed-in homepage. ### Back-end There was major reorganization done in the back-end by Maria. The database information was moved to another go package called 'storage.go', where functions related to accessing a database row, updating database information, checking the day, and more was done. This left all the HTTP POST and GET requests in 'main.go', with functions from storage being called within those requests. There were also appropriate test functions created in a file called 'storage_test.go', all developed by Maria. With the front-end already partially linked to the back-end through the userpage, an essential goal was to stitch the rest of the program together. This responsibility fell on Alexia, as she was the one who linked the two parts of the program initially. Three essential locations to do this was in 'eat cookie', 'past history', and 'user profile'. The back-end worked to make appropriate GET and POST requests for these pages, completing the link by adding to in the Typescript of those pages. Some POST and GET requests included finding/creating the user in the database, retrieving variables that the front-end needs about the user, and more. ## Testing ### Front-end Front-end tests primarily targeted the end-to-end functionality of the web application, using Cypress's HTTP functionalities to query and visit webpages, navigate the Document Object Model (DOM) and interacting through Javascript with the various components/elements on the page. Our tests unit + end-to-end testing consists of: - Visiting the page on its corresponding network port, checking to see if the Fortune Cookie application is what has been returned. - Attempting to visit the "User homepage" while not being signed in, checking returned DOM objects to see if the box containing the Google Sign-in option is present. - Attempting to access content on the "User profile" page, which should not be possible when not signed in - Attempting to "eat" a cookie (which gives you a fortune) as an unauthenticated user, which should fail and instead redirect to the Google Sign-in. - Accessing past fortunes and checking if the table gets populated if not signed in. In the future, further testing would implement Google authentication tokens within the Cypress testing framework to more broadly test the functionality of the application, with activities that signed-in users can carry out. ### Back-end Backend unit testing involves various functions that ensure that database integrity is maintained and behaves appropriately with new user creation, fortune creation, submission flags, etc. The full list of tests, along with their documentation can be found at: [https://github.com/mazohu/fortune-cookie/blob/main/back-end/storage/storage.go](https://github.com/mazohu/fortune-cookie/blob/main/back-end/storage/storage.go) - `func dataBaseTesting(username string, em string, uID string)` - `func fortuneTimerTesting(userPointer Users)` ## API Documentation ### Back-end `app.Post("/api/user/populate", func(c *fiber.Ctx) error` : Receives the username, email, and user ID from the front-end when logged in, and prompts for either creating a new entry in the users database or retreiving an existing user. `app.Post("/api/user/submitFortune", func(c *fiber.Ctx) error` : Receives a new fortune from the front-end, storing it in the fortunes database if it has been more than a day. `app.Get("/api/user/frontend/getFortune", func(c *fiber.Ctx) error` : In response to requesting a new fortune, this Get request sends a new, random fortune to the front-end. `app.Get("/api/user/frontend/fid", func(c *fiber.Ctx) error` : Sends a list of the current user's stored received fortunes to the front-end. `app.Get("/api/user/frontend/lastdate", func(c *fiber.Ctx) error` : Sends the lastdate (which is the current user's LastTime value but in a readable, string format) to the front-end. `app.Get("/api/user/frontend/submitted", func(c *fiber.Ctx) error` : Sends the current user's Submitted value to the front-end. `app.Get("/api/user/frontend/todayfortune", func(c *fiber.Ctx) error` : Sends the current user's LastFortune value to the front-end. `app.Get("/api/user/frontend/lastTime", func(c *fiber.Ctx) error` : Sends the current user's LastTime value to the front-end. `func clearDatabase(dbfile string)` : Deletes the entire database, mostly used for testing purposes. --- `func InitStorage(file string)()` : Creates or opens the sqlite database described by file and connects to this database. Because this function also populates the database with default fortunes and seeds the random number generator used in ReceiveFortune, this function should be called every time the server starts. `func GetUser(user User)()` : Creates or gets the User described by user and updates the global CurrentUser to point to this User. Since this function modifies or queries the User table in the database, it is necessary to pass a User with an initialized user ID. `func GetSubmit() bool` : Returns the CurrentUser's Submitted field. It is false if the user has not submitted and true otherwise. `func GetLastTime() time.Time` : Returns the LastTime that the CurrentUser submitted a fortune. `func GetLastFortune() string` : Returns the content of the last fortune received by the CurrentUser as a string. `func CheckToday()` : Checks whether the CurrentUser can submit today and, if true, updates the CurrentUser's Submitted and LastFortune fields and saves them to the database. `func SubmitFortune(content string)(error)` : Updates the fortune database with a fortune only if the user has not yet submitted a fortune. It creates a new Fortune with ID equal to the hash of content and content equal to the argument. If the operation fails, it returns an error. `func ReceiveFortune()(Fortune, error)` : Returns a random fortune not yet received by the user or an error if the database query fails. `func GetReceivedFortunes()([]Fortune, error)` : Returns the list of fortunes that the user has received or an error if the database query fails. `func GetFortunesNotReceived()([]Fortune, error)` : Returns the list of fortunes not received by the user or an error if the database query fails. `func FormatDate(ourTime time.Time)(string)` : Returns the date ourTime as a string with the format Month Day, Year. `func hashFortune(fortune string) (uint32)` : Private function which returns the hash of the string fortune. `func canSubmit()(bool)` : Private function which returns true if today's date is different than the one stored in LastTime and false otherwise.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully