-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from COS301-SE-2024/feat/new-e2e-tests
Feat/new e2e tests
- Loading branch information
Showing
13 changed files
with
267 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: Deployment | ||
|
||
on: | ||
workflow_run: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
- name: Make db env file | ||
uses: SpicyPizza/[email protected] | ||
with: | ||
envkey_POSTGRES_PASSWORD : ${{ secrets.POSTGRES_PASSWORD }} | ||
envkey_POSTGRES_USER : ${{ secrets.POSTGRES_USER }} | ||
envkey_POSTGRES_DB : ${{ secrets.POSTGRES_DB }} | ||
directory: . | ||
file_name: db.env | ||
fail_on_empty: false | ||
- name: Make api env files | ||
uses: SpicyPizza/[email protected] | ||
with: | ||
envkey_DATABASE_URL : ${{ secrets.DATABASE_URL }} | ||
envkey_DATABASE_PORT : ${{ secrets.DATABASE_PORT }} | ||
envkey_DATABASE_NAME : ${{ secrets.DATABASE_NAME }} | ||
envkey_DATABASE_USER : ${{ secrets.DATABASE_USER }} | ||
envkey_DATABASE_PASSWORD : ${{ secrets.DATABASE_PASSWORD }} | ||
envkey_COMPANY_EMAIL : ${{ secrets.COMPANY_EMAIL }} | ||
envkey_COMPANY_AUTH : ${{ secrets.COMPANY_AUTH }} | ||
directory: . | ||
file_name: api.env | ||
fail_on_empty: false | ||
- name: Make fe env files | ||
uses: SpicyPizza/[email protected] | ||
with: | ||
envkey_API_URL : ${{ secrets.API_URL }} | ||
directory: . | ||
file_name: fe.env | ||
fail_on_empty: false | ||
|
||
- name: Docker compose build | ||
run: | | ||
cd $GITHUB_WORKSPACE | ||
docker compose build | ||
- name: Make it a tar file | ||
run: | | ||
cd $GITHUB_WORKSPACE | ||
docker save -o frontend.tar dispute-resolution-engine-frontend:latest | ||
docker save -o api.tar api | ||
docker save -o postgres.tar postgres | ||
- name: Install wireguard | ||
run: sudo apt-get install wireguard | ||
|
||
- name: Create WG Config | ||
run: | | ||
sed -i -e "s@{{WG_PRIVATEKEY}}@${{ secrets.WG_PRIVATEKEY }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sed -i -e "s@{{WG_ADDRESS}}@${{ secrets.WG_ADDRESS }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sed -i -e "s@{{WG_DNS}}@${{ secrets.WG_DNS }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sed -i -e "s@{{WG_PUBLICKEY}}@${{ secrets.WG_PUBLICKEY }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sed -i -e "s@{{WG_ALLOWEDIPS}}@${{ secrets.WG_ALLOWEDIPS }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sed -i -e "s@{{WG_ENDPOINT}}@${{ secrets.WG_ENDPOINT }}@" $GITHUB_WORKSPACE/tunnel.conf | ||
sudo cp $GITHUB_WORKSPACE/tunnel.conf /etc/wireguard/ | ||
- name: WG Creating Tunnel | ||
run: | | ||
sudo apt install resolvconf | ||
wg-quick up $GITHUB_WORKSPACE/tunnel.conf | ||
- name: Send through the docker container using scp | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
port: ${{ secrets.SSH_PORT }} | ||
source: "api.tar,frontend.tar,postgres.tar,docker-compose.yaml" | ||
target: ./ | ||
- name: Spin up docker image | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
port: ${{ secrets.SSH_PORT }} | ||
script: | | ||
docker load -i frontend.tar | ||
docker load -i api.tar | ||
docker load -i postgres.tar | ||
docker-compose up -d | ||
cypress-test: | ||
container: | ||
image: cypress/included | ||
needs: deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cypress run | ||
uses: cypress-io/github-action@v2 | ||
with: | ||
wait-on: 'http://capstone-dre.dns.net.za' | ||
wait-on-timeout: 300 | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,6 @@ name: Go Test | |
run-name: ${{ github.actor }} at ${{ github.event_name }} event | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
- release | ||
- dev | ||
types: | ||
- opened | ||
- reopened | ||
jobs: | ||
go-test: | ||
runs-on: ubuntu-latest | ||
|
@@ -21,4 +13,8 @@ jobs: | |
- name: Run go test | ||
run: | | ||
cd api/__tests__ | ||
go test | ||
go test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,6 @@ name: Jest-Test | |
run-name: ${{ github.actor }} at ${{ github.event_name }} event | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
- release | ||
- dev | ||
types: | ||
- opened | ||
- reopened | ||
jobs: | ||
jest-test: | ||
runs-on: ubuntu-latest | ||
|
@@ -28,4 +20,8 @@ jobs: | |
- name: Run jest | ||
run: | | ||
cd frontend | ||
yarn test | ||
yarn test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Unit-And-Integration-Tests | ||
run-name: ${{ github.actor }} at ${{ github.event_name }} event | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
setup server: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18.20.3' | ||
- name: Install dependencies | ||
run: | | ||
cd frontend | ||
npm install -g yarn | ||
yarn | ||
- name: Build Docker | ||
run: | | ||
docker compose build | ||
docker compose up -d | ||
run jest tests: | ||
runs-on: ubuntu-latest | ||
depends-on: setup server | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18.20.3' | ||
- name: Install dependencies | ||
run: | | ||
cd frontend | ||
npm install -g yarn | ||
yarn | ||
- name: Run jest | ||
run: | | ||
cd frontend | ||
yarn test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
run go tests: | ||
runs-on: ubuntu-latest | ||
depends-on: setup server | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run go test | ||
run: | | ||
cd api/__tests__ | ||
go test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package api | ||
|
||
import ( | ||
"api/handlers" | ||
"api/db" // Import the package that contains the db symbo | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// MockResponseWriter is used to capture the HTTP response | ||
type MockResponseWriter struct { | ||
httptest.ResponseRecorder | ||
} | ||
|
||
func TestCreateUser(t *testing.T) { | ||
DB := db.Init() | ||
// Example of a valid request body | ||
validRequestBody := `{"first_name":"John","surname":"Doe","birthdate":"1990-01-01","nationality":"Country","email":"[email protected]"}` | ||
// Example of an invalid request body (incomplete JSON) | ||
invalidRequestBody := `{"first_name":"John"` | ||
|
||
tests := []struct { | ||
name string | ||
body string | ||
expectedStatus int | ||
}{ | ||
{"Valid Request", validRequestBody, http.StatusOK}, | ||
{"Invalid Request", invalidRequestBody, http.StatusBadRequest}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
request, err := http.NewRequest("POST", "/createuser", strings.NewReader(tt.body)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Use httptest.ResponseRecorder to capture the response | ||
responseRecorder := httptest.NewRecorder() | ||
handler := handlers.New(DB) | ||
|
||
// Serve the HTTP request to our handler | ||
handler.CreateUser(responseRecorder, request) | ||
|
||
// Check the status code is what we expect | ||
if status := responseRecorder.Code; status != tt.expectedStatus { | ||
t.Errorf("handler returned wrong status code: got %v want %v", | ||
status, tt.expectedStatus) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package api | ||
|
||
import ( | ||
"api/db" | ||
"api/handlers" | ||
"net/http" | ||
"github.com/gorilla/mux" | ||
|
||
"testing" | ||
) | ||
|
||
type MockStorage struct{} | ||
|
||
func TestInit(t *testing.T) { | ||
DB := db.Init() | ||
if DB == nil { | ||
t.Errorf("Expected db to be initialized, got nil") | ||
} | ||
h := handlers.New(DB) | ||
router := mux.NewRouter() | ||
|
||
router.HandleFunc("/createAcc", h.CreateUser).Methods(http.MethodPost) | ||
router.HandleFunc("/login", h.LoginUser).Methods(http.MethodPost) | ||
|
||
} |
Oops, something went wrong.