From d7d02ea491f6f97b381ca5b1b3b812a5a48224e1 Mon Sep 17 00:00:00 2001 From: Andrew Kasper Date: Thu, 26 Sep 2024 13:45:21 -0400 Subject: [PATCH] WIP Saving before switching dev machines --- spec/Outline.txt | 143 ++++++++++++++++++++-- spec/test_test.go | 299 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 378 insertions(+), 64 deletions(-) diff --git a/spec/Outline.txt b/spec/Outline.txt index 0410255..7aa9e14 100644 --- a/spec/Outline.txt +++ b/spec/Outline.txt @@ -9,24 +9,149 @@ Describe: Reading code systems from the application Given the service is populated with data AND the server is running - Context 1A: + Context 1a: Given a valid user AND has access to the api - +# Base + Test 1: + When I GET an endpoint that does not exist + Then Status Code 400 +# Code Systems + Test 2: + When I GET “ALL code systems” + Then Status Code 200 + AND Response body contains ALL code systems + + Test 3a: + When I GET code-systems by {id} with a VALID id + Then status code 200 + AND response body contains correct code-system + + Test 3b: + When I GET code-systems by {id} with an INVALID id + Then status code 400 +# Code Systems Concepts + Test 4: + When I GET all code systems Concepts + Then status code 200 + AND response body contains all Code Systems Concepts + + Test 5: + When I GET a code systems concept by ID with a VALID ID + Then status code 200 + AND response body contains the correct code system + + Test 6: + When I GET a code systems concept by ID with an INVALID ID + Then Status code 400 +# Value Sets Test: - When I get the code systems index endpoint + When I GET api/value-sets/ Then Status Code 200 - AND Response body contains multiple code systems + AND response body returns ALL value sets Test: - When I GET an endpoint that does not exist + When I GET a value set by ID with a VALID id + Then status code 200 + AND response body contains the correct value set + + Test: + When I GET a value set by ID with an INVALID ID + Then Status code 400 + + Test: + When I GET a value sets version based on its oid ("GET /api/value-sets/{oid}/versions") with a VALID oid + Then status code 200 + AND response body contains the value set's CORRECT version + + Test: + When I GET a value sets version based on its oid ("GET /api/value-sets/{oid}/versions") with an INVALID oid + Then status code 400 +# Value Set versions + Test: + When I get the VALUE sets versions by ID endpoint using a VALID ID + Then Status Code 200 + AND Response Body contains the versions of the CORRECT value set + + Test: + When I get the VALUE sets versions by ID endpoint using an INVALID ID + Then Status Code 400 +# Views + Test 3: + When I GET “ALL Views” + Then Status Code 200 + AND Response body contains ALL Views + + Test 6a: + When I GET ViewByID with a valid ID + Then Status Code 200 + AND response body contains the correct View + + Test 6b: + When I GET ViewByID with an invalid ID + Then Status Code 400 +# VIEW Versions + Test: + When I get the VIEW versions by ID endpoint using a VALID ID + Then Status Code 200 + AND Response Body contains the versions of the CORRECT view + + Test: + When I get the VIEW versions by ID endpoint using an INVALID ID + Then Status Code 400 + + Test: + When I get the VIEW versions by VIEW ID endpoint using a VALID ID + Then Status Code 200 + AND Response Body contains the versions of the CORRECT view id + + Test: + When I get the VIEW versions by VIEW ID endpoint using an INVALID ID + Then Status Code 400 +# Value Set Concepts + Test: + When I get the VALUE SET CONCEPTS by ID endpoint using a VALID ID + Then Status Code 200 + AND Response Body contains the correct VALUE SET CONCEPTS + + Test: + When I get the VALUE SET CONCEPTS by ID endpoint using an INVALID ID + Then Status Code 400 + + Test: + When I get the VALUE SET CONCEPTS through VALUE SET VERSION by the VERSION ID endpoint ("GET /api/value-set-concepts/value-set-version/{valueSetVersionId}") using a VALID ID + Then Status Code 200 + AND Response Body contains the correct VALUE SET CONCEPTS + + Test: + When I get the VALUE SET CONCEPTS through VALUE SET VERSION by the VERSION ID using an INVALID ID Then Status Code 400 Test: - When I get the code systems index by OID endpoint using a valid OID + When I get the VALUE SET CONCEPTS through the CODE SYSTEM by the CODE SYSTEM ID endpoint using a VALID ID Then Status Code 200 - AND Response Body contains the desired code system + AND Response Body contains the correct VALUE SET CONCEPTS + + Test: + When I get the VALUE SET CONCEPTS through the CODE SYSTEM by the CODE SYSTEM ID endpoint using an INVALID ID + Then Status Code 400 +# Miscellaneous + Test: + When I GET the TOGGLE BANNER endpoint with an ACTION, using a VALID ACTION + Status Code 200 + The Action is properly taken + + Test: + When I GET the TOGGLE BANNER endpoint with an ACTION, using an INVALID ACTION + Status Code 400 + The Action is not taken + + Test: + When I GET the LOAD HOT TOPICS endpoint + Status Code 200 + The HOT TOPICS are properly loaded Test: - When I get the code systems index by OID endpoint using a invalid OID - Then Status Code 400 \ No newline at end of file + When I GET the SEARCH RESULTS + Status Code 200 + The response body contains the proper search RESULTS diff --git a/spec/test_test.go b/spec/test_test.go index c98e74a..a32e501 100644 --- a/spec/test_test.go +++ b/spec/test_test.go @@ -1,73 +1,262 @@ package main_test -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -type AppConfig struct { - Host string - Port int - Username string - Password string +import { + "github/onsi/ginkgo/v2" } -type User struct { - Username string - Password string - Request string +ENDPOINTS = [ + "endpoint/1", + +] + +var _ = Describe("[PHIN VADS API]", func() { + Context("Given a running phinvads-go environment that has been properly populated", func() { + BeforeAll(func() { + // spin up environment if it's not already running + // populate database + }) + + + }) +}) + +// package main_test + +// import ( +// . "github.com/onsi/ginkgo/v2" +// . "github.com/onsi/gomega" +// ) + +// type AppConfig struct { +// Host string +// Port int +// Username string +// Password string +// } + +// type User struct { +// Username string +// Password string +// Request string +// } + +// var app = AppConfig{ +// Host: "localhost", +// Port: 5432, +// Username: "postgres", +// Password: "password", +// } + +// var _ = Describe("Reading code systems from the application", func() { +// BeforeEach(func() { +// FetchApi() +// }) +// Context("GIVEN the service is started", func() { +// var appStart *app // Assuming App is a type defined in phinvads +// Context("GIVEN the database loads successfully", func() { +// BeforeEach(func() { +// // Initialize app here if needed +// }) +// Context("GIVEN a valid user with access to the API", func() { +// var user *User +// BeforeAll(func() { +// user = &User{ +// Username: "testuser", +// Password: "testpassword", +// } +// }) +// Context("WHEN the user requests all code systems", func() { +// user.Request = "/api/code-systems" +// It("THEN return a list of all code systems", func() { +// Expect(codestystemslist).To(Equal("codestystemslist")) +// }) +// }) +// Context("WHEN the user requests a specific code system by OID", func() { +// user.Request = "/api/code-systems/{oid}" +// It("THEN return the desired code system", func() { +// Expect(codesystem).To(Equal("codesystem")) +// }) +// }) +// Context("WHEN the user requests a code system using an INVALID OID", func() { +// user.Request = "/api/code-systems/zero" +// It("THEN return a 400 error", func() { +// Expect(statuscode).To(Equal(400)) +// }) +// }) +// Context("WHEN the user requests a non-existant endpoint", func() { +// user.Request = "/api/invalid-endpoint" +// It("THEN return a 404 error", func() { +// Expect(statuscode).To(Equal(404)) +// }) +// }) +// }) +// }) +// }) +// }) + +package main_test + +import { + "github/onsi/ginkgo/v2" } -var app = AppConfig{ - Host: "localhost", - Port: 5432, - Username: "postgres", - Password: "password", +// These endpoints should respond to simple GET requests with 200 and a response body +const GETTABLE_ENDPOINTS = [ + "/", + "/assets/", + "/api", + "/api/code-systems", + "/api/code-system-concepts", + "/api/value-sets", + "/api/views", + "/load-hot-topics", + "/search" +] + +// These endpoints have show-type response bodies +// The ID to be passed in to these specs is acquired from the corresponding index action +const GETTABLE_SHOW_ENDPOINTS_WITH_PREDICTABLE_IDS = [ + "code-systems", "code-system-concepts", "value-sets", "views" +] + +func IsValidGetRequest(response) { + return ( + response.code == '200' && + response.body.length != 0 + JSON.parse(response.body).errors.length == 0 + ) } -var _ = Describe("Reading code systems from the application", func() { - BeforeEach(func() { - FetchApi() - }) - Context("GIVEN the service is started", func() { - var appStart *app // Assuming App is a type defined in phinvads - Context("GIVEN the database loads successfully", func() { +var _ = Describe("[PHIN VADS API]", func() { + Context("Given an API environment that has been populated with data", func() { + BeforeEach(func { + // load data into the environment + // dependent upon sample dataset, may require a BeforeAll + }) + + Context("Given that I do not have an API key", func() { + Context("When I GET the 'create API key' endpoint", func() { + // pending + // describe steps for getting an API key + }) + + Context("When I GET any other valid endpoint", func() { + // generate specs for each possible endpoint + // I should get a 400 + // response body should say "You need an API key idiot" + }) + }) + + Context("Given that I have a valid API key", func() { BeforeEach(func() { - // Initialize app here if needed + // generate an API key }) - Context("GIVEN a valid user with access to the API", func() { - var user *User - BeforeAll(func() { - user = &User{ - Username: "testuser", - Password: "testpassword", - } - }) - Context("WHEN the user requests all code systems", func() { - user.Request = "/api/code-systems" - It("THEN return a list of all code systems", func() { - Expect(codestystemslist).To(Equal("codestystemslist")) - }) + + Context("When I attempt to GET an invalid endpoint", func() { + BeforeEach(func() { + response = doTheThing("/known/invalid/endpoint"); }) - Context("WHEN the user requests a specific code system by OID", func() { - user.Request = "/api/code-systems/{oid}" - It("THEN return the desired code system", func() { - Expect(codesystem).To(Equal("codesystem")) - }) + + It("Then the request should fail", func() { + Expect(response.code).To(Equal('404')); + Expect(response.body).To(BeZero())); }) - Context("WHEN the user requests a code system using an INVALID OID", func() { - user.Request = "/api/code-systems/zero" - It("THEN return a 400 error", func() { - Expect(statuscode).To(Equal(400)) - }) + }) + + Context("When I GET /" func() { + BeforeEach(func() { + response = doTheThing("/") }) - Context("WHEN the user requests a non-existant endpoint", func() { - user.Request = "/api/invalid-endpoint" - It("THEN return a 404 error", func() { - Expect(statuscode).To(Equal(404)) - }) + + + + }) + + Context("When I GET /assets/", func() { + BeforeEach(func() { + response = doTheThing("/assets/") }) + + It("Then the response should succeed") + It("Then the response should be compressed") + It("Then the response should be UTF-8 encoded") }) + }) }) + }) + +// package main_test + +// import ( +// . "github.com/onsi/ginkgo/v2" +// . "github.com/onsi/gomega" +// ) + +// type AppConfig struct { +// Host string +// Port int +// Username string +// Password string +// } + +// type User struct { +// Username string +// Password string +// Request string +// } + +// var app = AppConfig{ +// Host: "localhost", +// Port: 5432, +// Username: "postgres", +// Password: "password", +// } + +// var _ = Describe("Reading code systems from the application", func() { +// BeforeEach(func() { +// FetchApi() +// }) +// Context("GIVEN the service is started", func() { +// var appStart *app // Assuming App is a type defined in phinvads +// Context("GIVEN the database loads successfully", func() { +// BeforeEach(func() { +// // Initialize app here if needed +// }) +// Context("GIVEN a valid user with access to the API", func() { +// var user *User +// BeforeAll(func() { +// user = &User{ +// Username: "testuser", +// Password: "testpassword", +// } +// }) +// Context("WHEN the user requests all code systems", func() { +// user.Request = "/api/code-systems" +// It("THEN return a list of all code systems", func() { +// Expect(codestystemslist).To(Equal("codestystemslist")) +// }) +// }) +// Context("WHEN the user requests a specific code system by OID", func() { +// user.Request = "/api/code-systems/{oid}" +// It("THEN return the desired code system", func() { +// Expect(codesystem).To(Equal("codesystem")) +// }) +// }) +// Context("WHEN the user requests a code system using an INVALID OID", func() { +// user.Request = "/api/code-systems/zero" +// It("THEN return a 400 error", func() { +// Expect(statuscode).To(Equal(400)) +// }) +// }) +// Context("WHEN the user requests a non-existant endpoint", func() { +// user.Request = "/api/invalid-endpoint" +// It("THEN return a 404 error", func() { +// Expect(statuscode).To(Equal(404)) +// }) +// }) +// }) +// }) +// }) +// })