diff --git a/usermodel-initial/pom.xml b/usermodel-initial/pom.xml index 4a5df7a..b0c236a 100644 --- a/usermodel-initial/pom.xml +++ b/usermodel-initial/pom.xml @@ -95,6 +95,15 @@ 2.3.6.RELEASE + + + + io.rest-assured + spring-mock-mvc + 3.3.0 + test + + diff --git a/usermodel-initial/src/main/java/com/lambdaschool/usermodel/SeedData.java b/usermodel-initial/src/main/java/com/lambdaschool/usermodel/SeedData.java index 50d2caa..8d7f4a8 100755 --- a/usermodel-initial/src/main/java/com/lambdaschool/usermodel/SeedData.java +++ b/usermodel-initial/src/main/java/com/lambdaschool/usermodel/SeedData.java @@ -11,6 +11,7 @@ import com.lambdaschool.usermodel.services.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -23,6 +24,12 @@ * after the application context has been loaded. */ @Transactional +@ConditionalOnProperty( + prefix = "command.line.runner", + value = "enabled", + havingValue = "true", + matchIfMissing = true +) @Component public class SeedData implements CommandLineRunner diff --git a/usermodel-initial/src/main/resources/application.properties b/usermodel-initial/src/main/resources/application.properties index 6467ccd..92abaad 100644 --- a/usermodel-initial/src/main/resources/application.properties +++ b/usermodel-initial/src/main/resources/application.properties @@ -17,7 +17,7 @@ spring.jpa.open-in-view=true # What do with the schema # drop n create table again, good for testing spring.jpa.hibernate.ddl-auto=create -spring.datasource.initialization-mode=always +spring.datasource.initialization-mode=never # # Good for production! # spring.jpa.hibernate.ddl-auto=update diff --git a/usermodel-initial/src/test/java/com/lambdaschool/usermodel/SeedData.java b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/SeedData.java new file mode 100644 index 0000000..90ea90d --- /dev/null +++ b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/SeedData.java @@ -0,0 +1,174 @@ +package com.lambdaschool.usermodel; + +import com.github.javafaker.Faker; +import com.github.javafaker.service.FakeValuesService; +import com.github.javafaker.service.RandomService; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import com.lambdaschool.usermodel.models.Useremail; +import com.lambdaschool.usermodel.services.RoleService; +import com.lambdaschool.usermodel.services.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Locale; + +/** + * SeedData puts both known and random data into the database. It implements CommandLineRunner. + *

+ * CoomandLineRunner: Spring Boot automatically runs the run method once and only once + * after the application context has been loaded. + */ +@Transactional +@ConditionalOnProperty( + prefix = "command.line.runner", + value = "enabled", + havingValue = "true", + matchIfMissing = true +) +@Component +public class SeedData + implements CommandLineRunner +{ + /** + * Connects the Role Service to this process + */ + @Autowired + RoleService roleService; + + /** + * Connects the user service to this process + */ + @Autowired + UserService userService; + + /** + * Generates test, seed data for our application + * First a set of known data is seeded into our database. + * Second a random set of data using Java Faker is seeded into our database. + * Note this process does not remove data from the database. So if data exists in the database + * prior to running this process, that data remains in the database. + * + * @param args The parameter is required by the parent interface but is not used in this process. + */ + @Transactional + @Override + public void run(String[] args) throws + Exception + { + userService.deleteAll(); + roleService.deleteAll(); + Role r1 = new Role("admin"); + Role r2 = new Role("user"); + Role r3 = new Role("data"); + + r1 = roleService.save(r1); + r2 = roleService.save(r2); + r3 = roleService.save(r3); + + // admin, data, user + User u1 = new User("admin Test", + "password", + "admin@lambdaschool.local"); + u1.getRoles() + .add(new UserRoles(u1, + r1)); + u1.getRoles() + .add(new UserRoles(u1, + r2)); + u1.getRoles() + .add(new UserRoles(u1, + r3)); + u1.getUseremails() + .add(new Useremail(u1, + "admin@email.local")); + u1.getUseremails() + .add(new Useremail(u1, + "admin@mymail.local")); + + userService.save(u1); + + // data, user + User u2 = new User("cinnamon Test", + "1234567", + "cinnamon@lambdaschool.local"); + u2.getRoles() + .add(new UserRoles(u2, + r2)); + u2.getRoles() + .add(new UserRoles(u2, + r3)); + u2.getUseremails() + .add(new Useremail(u2, + "cinnamon@mymail.local")); + u2.getUseremails() + .add(new Useremail(u2, + "hops@mymail.local")); + u2.getUseremails() + .add(new Useremail(u2, + "bunny@email.local")); + userService.save(u2); + + // user + User u3 = new User("barnbarn Test", + "ILuvM4th!", + "barnbarn@lambdaschool.local"); + u3.getRoles() + .add(new UserRoles(u3, + r2)); + u3.getUseremails() + .add(new Useremail(u3, + "barnbarn@email.local")); + userService.save(u3); + + User u4 = new User("puttat Test", + "password", + "puttat@school.lambda"); + u4.getRoles() + .add(new UserRoles(u4, + r2)); + userService.save(u4); + + User u5 = new User("misskitty Test", + "password", + "misskitty@school.lambda"); + u5.getRoles() + .add(new UserRoles(u5, + r2)); + userService.save(u5); + + if (false) + { + // using JavaFaker create a bunch of regular users + // https://www.baeldung.com/java-faker + // https://www.baeldung.com/regular-expressions-java + + FakeValuesService fakeValuesService = new FakeValuesService(new Locale("en-US"), + new RandomService()); + Faker nameFaker = new Faker(new Locale("en-US")); + + for (int i = 0; i < 25; i++) + { + new User(); + User fakeUser; + + fakeUser = new User(nameFaker.name() + .username(), + "password", + nameFaker.internet() + .emailAddress()); + fakeUser.getRoles() + .add(new UserRoles(fakeUser, + r2)); + fakeUser.getUseremails() + .add(new Useremail(fakeUser, + fakeValuesService.bothify("????##@gmail.com"))); + userService.save(fakeUser); + } + } + } +} \ No newline at end of file diff --git a/usermodel-initial/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTestNoDb.java b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTestNoDb.java new file mode 100644 index 0000000..1de0c09 --- /dev/null +++ b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/controllers/UserControllerTestNoDb.java @@ -0,0 +1,189 @@ +package com.lambdaschool.usermodel.controllers; + +import com.lambdaschool.usermodel.UserModelApplicationTesting; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import com.lambdaschool.usermodel.models.Useremail; +import com.lambdaschool.usermodel.services.UserService; +import io.restassured.module.mockmvc.RestAssuredMockMvc; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; +@RunWith(SpringRunner.class) +@WithMockUser(username = "admin", +roles = {"USER", "ADMIN"}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, +classes = UserModelApplicationTesting.class, +properties = {"command.line.runner.enabled=false"}) +@AutoConfigureMockMvc +public class UserControllerTestNoDb +{ + @Autowired + private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @MockBean + private UserService userService; + + private List userList = new ArrayList<>(); + + @Before + public void setUp() throws Exception + { + userList = new ArrayList<>(); + + Role r1 = new Role("admin"); + Role r2 = new Role("user"); + Role r3 = new Role("data"); + + r1.setRoleid(1); + r2.setRoleid(2); + r3.setRoleid(3); + + // admin, data, user + User u1 = new User("admin Test", + "password", + "admin@lambdaschool.local"); + u1.setUserid(10); + u1.getRoles() + .add(new UserRoles(u1, + r1)); + u1.getRoles() + .add(new UserRoles(u1, + r2)); + u1.getRoles() + .add(new UserRoles(u1, + r3)); + u1.getUseremails() + .add(new Useremail(u1, + "admin@email.local")); + u1.getUseremails().get(0).setUseremailid(11); + + u1.getUseremails() + .add(new Useremail(u1, + "admin@mymail.local")); + u1.getUseremails().get(1).setUseremailid(12); + + + userList.add(u1); + + // data, user + User u2 = new User("cinnamon Test", + "1234567", + "cinnamon@lambdaschool.local"); + u2.setUserid(20); + u2.getRoles() + .add(new UserRoles(u2, + r2)); + u2.getRoles() + .add(new UserRoles(u2, + r3)); + u2.getUseremails() + .add(new Useremail(u2, + "cinnamon@mymail.local")); + u2.getUseremails().get(0).setUseremailid(21); + u2.getUseremails() + .add(new Useremail(u2, + "hops@mymail.local")); + u2.getUseremails().get(1).setUseremailid(22); + + userList.add(u2); + + RestAssuredMockMvc.webAppContextSetup(webApplicationContext); + + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) + .apply(SecurityMockMvcConfigurers.springSecurity()) + .build(); + } + + @After + public void tearDown() throws Exception + { + } + + @Test + public void listAllUsers() throws Exception + { + String apiURL = "http://localhost:2019/users/users"; + Mockito.when(userService.findAll()) + .thenReturn(userList); + + RequestBuilder rb = MockMvcRequestBuilders.get(apiURL) + .accept(MediaType.APPLICATION_JSON); + MvcResult r = mockMvc.perform(rb) + .andReturn(); + String tr = r.getResponse() + .getContentAsString(); + + ObjectMapper mapper = new ObjectMapper(); + String er = mapper.writeValueAsString(userList); + + System.out.println(er); + assertEquals(er, tr); + } + + @Test + public void getUserById() + { + } + + @Test + public void getUserByName() + { + } + + @Test + public void getUserLikeName() + { + } + + @Test + public void addNewUser() + { + } + + @Test + public void updateFullUser() + { + } + + @Test + public void updateUser() + { + } + + @Test + public void deleteUserById() + { + } + + @Test + public void getCurrentUserInfo() + { + } +} \ No newline at end of file diff --git a/usermodel-initial/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTestNoDB.java b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTestNoDB.java new file mode 100644 index 0000000..4fbeccc --- /dev/null +++ b/usermodel-initial/src/test/java/com/lambdaschool/usermodel/services/UserServiceImplTestNoDB.java @@ -0,0 +1,310 @@ +package com.lambdaschool.usermodel.services; + +import com.github.javafaker.Faker; +import com.github.javafaker.service.FakeValuesService; +import com.github.javafaker.service.RandomService; +import com.lambdaschool.usermodel.UserModelApplicationTesting; +import com.lambdaschool.usermodel.exceptions.ResourceNotFoundException; +import com.lambdaschool.usermodel.models.Role; +import com.lambdaschool.usermodel.models.User; +import com.lambdaschool.usermodel.models.UserRoles; +import com.lambdaschool.usermodel.models.Useremail; +import com.lambdaschool.usermodel.repository.RoleRepository; +import com.lambdaschool.usermodel.repository.UserRepository; +import com.lambdaschool.usermodel.repository.UseremailRepository; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.After; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoSettings; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Optional; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = UserModelApplicationTesting.class, + properties = {"command.line.runner.enabled=false"}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class UserServiceImplTestNoDB +{ + @Autowired + private UserService userService; + + @MockBean + private UserRepository userRepository; + + @MockBean + private RoleRepository roleRepository; + + @MockBean + private RoleService roleService; + + @MockBean + HelperFunctions helperFunctions; + + private List userList = new ArrayList<>(); + + @Before + public void setUp() throws Exception + { + userList = new ArrayList<>(); + + Role r1 = new Role("admin"); + Role r2 = new Role("user"); + Role r3 = new Role("data"); + + r1.setRoleid(1); + r2.setRoleid(2); + r3.setRoleid(3); + + // admin, data, user + User u1 = new User("admin Test", + "password", + "admin@lambdaschool.local"); + u1.setUserid(10); + u1.getRoles() + .add(new UserRoles(u1, + r1)); + u1.getRoles() + .add(new UserRoles(u1, + r2)); + u1.getRoles() + .add(new UserRoles(u1, + r3)); + u1.getUseremails() + .add(new Useremail(u1, + "admin@email.local")); + u1.getUseremails().get(0).setUseremailid(11); + + u1.getUseremails() + .add(new Useremail(u1, + "admin@mymail.local")); + u1.getUseremails().get(1).setUseremailid(12); + + + userList.add(u1); + + // data, user + User u2 = new User("cinnamon Test", + "1234567", + "cinnamon@lambdaschool.local"); + u2.setUserid(20); + u2.getRoles() + .add(new UserRoles(u2, + r2)); + u2.getRoles() + .add(new UserRoles(u2, + r3)); + u2.getUseremails() + .add(new Useremail(u2, + "cinnamon@mymail.local")); + u2.getUseremails().get(0).setUseremailid(21); + u2.getUseremails() + .add(new Useremail(u2, + "hops@mymail.local")); + u2.getUseremails().get(1).setUseremailid(22); + + userList.add(u2); + + MockitoAnnotations.initMocks(this); + } + + @After + public void tearDown() throws Exception + { + } + + @Test + public void a_findUserById() + { + Mockito.when(userRepository.findById(20L)) + .thenReturn(Optional.of(userList.get(1))); + + assertEquals("cinnamon Test".toLowerCase(), + userService.findUserById(20) + .getUsername()); + } + + @Test(expected = ResourceNotFoundException.class) + public void aa_notfindUserById() + { + Mockito.when(userRepository.findById(300L)) + .thenThrow(ResourceNotFoundException.class); + + assertEquals("cinnamon Test".toLowerCase(), + userService.findUserById(300) + .getUsername()); + } + + + @Test + public void b_findByNameContaining() + { + Mockito.when(userRepository.findByUsernameContainingIgnoreCase("admin")) + .thenReturn(userList); + + assertEquals(2, userService.findByNameContaining("admin").size()); + } + + @Test(expected = ResourceNotFoundException.class) + public void bb_findByNameContainingFail() + { + Mockito.when(userRepository.findByUsernameContainingIgnoreCase("asdfwsadf")) + .thenThrow(ResourceNotFoundException.class); + + assertEquals(0, + userService.findByNameContaining("asdfwsadf").size()); + } + + @Test + public void c_findAll() + { + Mockito.when(userRepository.findAll()) + .thenReturn(userList); + + assertEquals(2, + userService.findAll().size()); + } + + @Test + public void d_delete() + { + Mockito.when(userRepository.findById(4L)) + .thenReturn(Optional.of(userList.get(0))); + + Mockito.doNothing() + .when(userRepository) + .deleteById(4L); + + userService.delete(4); + assertEquals(2, + userList.size()); + } + + @Test(expected = ResourceNotFoundException.class) + public void dd_deleteFailed() + { + Mockito.when(userRepository.findById(234L)) + .thenReturn(Optional.empty()); + + Mockito.doNothing() + .when(userRepository) + .deleteById(234L); + + userService.delete(234); + assertEquals(2, + userList.size()); + } + + @Test + public void e_findByName() + { + Mockito.when(userRepository.findByUsername("admin Test".toLowerCase())) + .thenReturn(userList.get(0)); + + assertEquals("admin Test".toLowerCase(), + userService.findByName("admin Test") + .getUsername()); + } + + @Test + public void f_save() + { + Role roleType1 = new Role("dog"); + roleType1.setRoleid(10); + + User u3 = new User("Indy Test", + "password", + "dog@lambdaschool.local"); + + u3.getRoles() + .add(new UserRoles(u3, + roleType1)); + + u3.getUseremails() + .add(new Useremail(u3, + "dog@email.local")); + u3.getUseremails().get(0).setUseremailid(31); + + u3.getUseremails() + .add(new Useremail(u3, + "admin@mymail.local")); + u3.getUseremails().get(1).setUseremailid(32); + + Mockito.when(userRepository.save(any(User.class))) + .thenReturn(u3); + Mockito.when(roleService.findRoleById(10L)) + .thenReturn(roleType1); + + User addUser = userService.save(u3); + assertNotNull(addUser); + assertEquals(addUser.getUsername().toLowerCase(), + addUser.getUsername().toLowerCase()); + } + + @Test + public void g_update() throws Exception + { + Role roleType1 = new Role("dog"); + roleType1.setRoleid(10); + + User u3 = new User("Indy Test123", + "password", + "dog@lambdaschool.local"); + u3.setUserid(30); + u3.getRoles() + .add(new UserRoles(u3, + roleType1)); + + u3.getUseremails() + .add(new Useremail(u3, + "dog@email.local")); + u3.getUseremails().get(0).setUseremailid(31); + + u3.getUseremails() + .add(new Useremail(u3, + "admin@mail.local")); + u3.getUseremails().get(1).setUseremailid(32); + + Mockito.when(helperFunctions.isAuthorizedToMakeChange(anyString())).thenReturn(true); + Mockito.when(userRepository.findById(30L)) + .thenReturn(Optional.of(userList.get(0))); + Mockito.when(roleRepository.findById(10L)) + .thenReturn(Optional.of(roleType1)); + + Mockito.when(userRepository.save(any(User.class))) + .thenReturn(u3); + + User addUser = userService.update(u3, 30); + + assertNotNull(addUser); + assertEquals(u3.getUsername(), addUser.getUsername()); + + } + + @Test + public void h_deleteAll() + { +// Mockito.when(userRepository.findAll()) +// .thenReturn(Optional.of(userList.get())); +// +// userList.deleteAll(); +// assertEquals(0, userList.size()); + } +} \ No newline at end of file diff --git a/usermodel-initial/src/test/resources/application.properties b/usermodel-initial/src/test/resources/application.properties new file mode 100644 index 0000000..92abaad --- /dev/null +++ b/usermodel-initial/src/test/resources/application.properties @@ -0,0 +1,34 @@ +# Configurations useful for working with H2 +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console +# +# We set a port that is not frequently used +server.port=${PORT:2019} +# +# Feature that determines what happens when no accessors are found for a type +# (and there are no annotations to indicate it is meant to be serialized). +spring.jackson.serialization.fail-on-empty-beans=false +# +# keeps a transaction inside of the same entity manager +# This property register an EntityManager to the current thread, +# so you will have the same EntityManager until the web request is finished. +spring.jpa.open-in-view=true +# +# What do with the schema +# drop n create table again, good for testing +spring.jpa.hibernate.ddl-auto=create +spring.datasource.initialization-mode=never +# +# Good for production! +# spring.jpa.hibernate.ddl-auto=update +# since we have our data in SeedData, do not also load it from data.sql +# spring.datasource.initialization-mode=never +# +# Used to set the date format for JSON Output +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss +spring.jackson.time-zone=America/Los_Angeles +# +# Turns off Spring Boot automatic exception handling +server.error.whitelabel.enabled=false +spring.mvc.throw-exception-if-no-handler-found=true +spring.resources.add-mappings=false diff --git a/usermodel-initial/src/test/resources/info/curl.txt b/usermodel-initial/src/test/resources/info/curl.txt new file mode 100644 index 0000000..8e6a532 --- /dev/null +++ b/usermodel-initial/src/test/resources/info/curl.txt @@ -0,0 +1,69 @@ +// admins access token = 56ab5075-de2e-43ba-a407-e52b8f267ac7 +// barnbarns access token = a87cdc74-7188-43d7-9c2e-f689841f083f + +// get admins access code +curl -X POST --user "lambda-client:lambda-secret" -d "grant_type=password&username=admin&password=password" http://localhost:2019/login + +// this works +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/users + +// get users access code +curl -X POST --user "lambda-client:lambda-secret" -d 'grant_type=password&username=barnbarn&password=ILuvM4th!' http://localhost:2019/login + +// this has an authentication error +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer a87cdc74-7188-43d7-9c2e-f689841f083f" http://localhost:2019/users/users + +// switch back to admins access code and this works +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/users + +// add snoopy as a user +curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" -d "{ \"username\":\"snoopy\", \"password\":\"password\", \"roleid\":"1" }" http://localhost:2019/users/user + +// look up users and find snoopy's id +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/users + +// delete snoopy user +curl -X DELETE -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/user/15 + +// verify that snoopy is deleted +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/user/15 + +// add ginger a new user +curl -X POST -H "Content-Type: application/json" -d "{\"username\": \"Ginger\", \"password\": \"EATEATEAT\"}" http://localhost:2019/createnewuser + +// add snoopy again with full information +curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" -d "{ \"username\": \"Snoopy\", \"password\": \"password\", \"userRoles\": [ { \"role\": { \"roleid\": 1 } } ], \"userphones\": [ { \"userphone\": \"myemail@local.home\" } ]}" http://localhost:2019/users/user + +// look at all users and verify that snoopy and ginger are available +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/users + +// revokes token for admin +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/oauth/revoke-token + +// this should fail with invalid token +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 56ab5075-de2e-43ba-a407-e52b8f267ac7" http://localhost:2019/users/users + +// get admins access code +curl -X POST --user "lambda-client:lambda-secret" -d "grant_type=password&username=admin&password=password" http://localhost:2019/login + +// look at all users and ginger's id +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 3d28337c-b699-4ae6-86fe-4961f42b1142" http://localhost:2019/users/users + +// add email to ginger +curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer 3d28337c-b699-4ae6-86fe-4961f42b1142" -d "{ \"userid\": 16, \"userphones\": [ { \"userphone\": \"whisker@home.local\" } ] }" http://localhost:2019/users/user/16 + +// look at all users and ginger's emails +curl -X GET -H "Accept: application/json" -H "Authorization: Bearer 3d28337c-b699-4ae6-86fe-4961f42b1142" http://localhost:2019/users/users + +*** using a different host + +// sign on admin when on heroku +curl -X POST --user "lambda-client:lambda-secret" -d "grant_type=password&username=admin&password=password" http://jrmmba-starthere.herokuapp.com/oauth/token + + +{ + "userid": 7, + "userphones": [ + { "userphone": "whisker@home.local"} + ] +} \ No newline at end of file