Skip to content

olnov/jacebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Acebook

The application uses:

  • maven to build the project
  • thymeleaf for templating
  • flyway to manage postgres db migrations
  • selenium for feature testing
  • faker to generate fake names for testing
  • junit4 for unit testing
  • auth0 and spring-security for authentication and user management

Below, you'll find specific learning objectives for each tool.

QuickStart Instructions

  • Fork and clone this repository to your machine
  • Open the codebase in an IDE like InteliJ or VSCode
  • Create a new Postgres database called acebook_springboot_development
  • Install Maven brew install maven
  • Set up Auth0 (you only need the "Create an Auth0 app" section)
    • NOTE: Each member of the team will need their own Auth0 app
  • Build the app and start the server, using the Maven command mvn spring-boot:run

The database migrations will run automatically at this point

  • Visit http://localhost:8080/ to sign up

Extending User Sign Up

The second migration creates a users table but, to start with, noting is ever put in there - when a user signs up via Auth0, a record is created in a table that Auth0 'owns' in the cloud. But, if you want your Posts to have authors (a one to many relationship between users and posts) you'll need your own record of each user.

It's not necessary to do this from the start but, once you're ready to implement the one to many relationship...

  1. Install localtunnel npm install -g localtunnel
  2. Choose a subdomain, perhaps one based on your team's name. It needs to be unique!
  3. Get a public URL for your app lt --port 8080 --subdomain <your-subdomain>
  4. Go to your Auth0 account and choose Actions on the left sidebar, then Flows
  5. Choose Post User Registtration from the main page body
  6. Click + next to Add Action and then, from the menu, choose Build from scratch
  7. On the pop up form..
    • Give your action a sensible name
    • The trigger should be set to Post User Registration
    • The runtime should be set to Node 18
    • Click Create
  8. Paste in the code below, then click Deploy
  9. Finally, go to your Auth0 application settings to update Allowed Callback Urls and Allowed Logout URLs with your new localtunnel URLs.

What your updated Auth0 URLs might look like

An image of the Auth0 fields for updating callback and logout URLs

Post User Registration Code

exports.onExecutePostUserRegistration = async (event, api) => {
  fetch("https://<your-domain>.loca.lt/users", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        username: event.user.email
      })
    }
  )
};

An image showing the JS code that is used in the post user registration action

Now, when a user signs up, an HTTP request will be sent to your locally running app and a user will be added to your local database whenever someone signs up. Test this by signing up then looking at the contents of your local users table.

NOTE: As mentioned above, each member of the team needs their own Auth0 app and they'll each need to do the above set up for users.

Running the tests

  • Install chromedriver using brew install chromedriver
  • Start the server in a terminal session mvn spring-boot:run
  • Open a new terminal session and navigate to the Acebook directory
  • Run your tests in the second terminal session with mvn test

All the tests should pass. If one or more fail, read the next section.

Common Setup Issues

The application is not running

For the feature tests to execute properly, you'll need to have the server running in one terminal session and then use a second terminal session to run the tests.

Chromedriver is in the wrong place

Selenium uses Chromedriver to interact with the Chrome browser. If you're on a Mac, Chromedriver needs to be in /usr/local/bin. You can find out where it is like this which chromedriver. If it's in the wrong place, move it using mv.

Chromedriver can't be opened

Your Mac might refuse to open Chromedriver because it's from an unidentified developer. If you see a popup at that point, dismiss it by selecting Cancel, then go to System Preferences, Security and Privacy, General. You should see a message telling you that Chromedriver was blocked and, if so, there will be an Open Anyway button. Click that and then re-try your tests.

Existing features

This app already has a few basic features

  • A user can sign up using Auth0
  • A signed up user can sign in
  • A signed in user can create posts at /posts
  • A signed in user can sign out at /logout

Design

This app uses the repository pattern. The repository pattern separates the business logic of models from the responsibility of connecting to the database and making queries. Take a look in the src/main/java/repository and you'll find PostRepository which generates and executes queries to Create, Read, Update and Delete (CRUD) posts. Depending on what you've built in the past, it might or might not feel familiar to you.

Initial learning goals

You don't need an in-depth knowledge of each dependency listed above. Once you can tick off these learning goals, you're ready to dive in. It's assumed that you can already TDD the Takeaway Challenge, or something of similar complexity, in Java. It's OK if you need to pause here with Acebook and learn how to do that now :)

Maven

  • I can explain what pom.xml is for
  • I can start the app using Maven

Thymeleaf

  • I can explain the code in posts/index.html
  • I can plan a new template that could be used for editing a post

Flyway

  • I can explain what a migration is
  • I can explain when migrations are run
  • I can explain the code in the two migration files in this directory /db/migration/
  • I can explain the naming convention for flyway migration files

Selenium

  • I can explain the code in SignUpTest.java
  • I can write a new feature test for unsuccessful sign up

Faker

  • I can explain what Faker does
  • I can explain why it's useful

JUnit4

  • I can explain the code in PostTest.java
  • I could add more test cases to PostTest.java

The repository pattern

  • I can explain the repository pattern

SpringBoot

  • I can diagram how this SpringBoot application handles GET "/posts"

Spring Security and Auth0

  • I can explain how this app is secured

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages