Skip to content

Commit

Permalink
Merge pull request #352 from COS301-SE-2024/release-20240811
Browse files Browse the repository at this point in the history
Release 20240811
  • Loading branch information
S3BzA authored Aug 11, 2024
2 parents 79b4d0e + 38f1eac commit 60cad5f
Show file tree
Hide file tree
Showing 124 changed files with 12,528 additions and 15,279 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cypress-test-basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on:
types:
- completed
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Run a basic command
run: echo "This is for workflow compliance"

cypress-test:
container:
image: cypress/included
Expand All @@ -19,6 +27,7 @@ jobs:
with:
wait-on: 'http://capstone-dre.dns.net.za'
wait-on-timeout: 300
working-directory: frontend
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/doco-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
defaults:
run:
working-directory: 'docs'
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build

- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build

deploy:
name: Deploy to GitHub Pages
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Run go test
run: |
cd api
go test ./... -v
go test ./...
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img src="./dre-docs/static/img/dre_banner.svg">
<img src="./docs/static/img/dre_banner.svg">
</div>

<div align="center">
Expand All @@ -8,7 +8,7 @@
<img src="https://github.com/COS301-SE-2024/Dispute-Resolution-Engine/actions/workflows/jest-test.yaml/badge.svg">
<img src="https://github.com/COS301-SE-2024/Dispute-Resolution-Engine/actions/workflows/lint.yaml/badge.svg">
<img src="https://github.com/COS301-SE-2024/Dispute-Resolution-Engine/actions/workflows/deployment.yaml/badge.svg">
<a href="https://codecov.io/gh/COS301-SE-2024/Dispute-Resolution-Engine" >
<a href="https://codecov.io/gh/COS301-SE-2024/Dispute-Resolution-Engine">
<img src="https://codecov.io/gh/COS301-SE-2024/Dispute-Resolution-Engine/branch/dev/graph/badge.svg?token=7qG24ym2EY"/>
</a>

Expand All @@ -29,6 +29,7 @@ Team Email: [[email protected]](mailto:[email protected])

- [Demo 1](https://www.canva.com/design/DAGG_C4gUMc/uzNI3y3cFbQE9oYkyZo3vw/edit?utm_content=DAGG_C4gUMc&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton)
- [Demo 2](https://www.canva.com/design/DAGI9uq7XF0/qvU7IogSTW3PETHPllxBAA/edit?utm_content=DAGI9uq7XF0&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton)
- [Demo 3](https://www.canva.com/design/DAGNfNQm-pE/PPbmWY4BbFiZja1LLa--Aw/edit?utm_content=DAGNfNQm-pE&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton)

# Project Management

Expand Down
24 changes: 14 additions & 10 deletions api/auditLogger/disputeProceedingsLogger.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package auditLogger

import (
"api/db"
"api/env"
"api/models"
"api/utilities"

"gorm.io/gorm"
)

type DisputeProceedingsLoggerInterface interface {
LogDisputeProceedings(proceedingType models.EventTypes, eventData map[string]interface{}) error
}


type DisputeProceedingsLogger struct {
DB *gorm.DB
EnvReader env.Env
Expand All @@ -19,16 +23,16 @@ type LogJson struct {
Json interface{}
}

func NewDisputeProceedingsLoggerDBInit() (DisputeProceedingsLogger,error) {
DB, err := db.Init()
if err != nil {
return DisputeProceedingsLogger{}, err
}
return DisputeProceedingsLogger{DB: DB, EnvReader: env.NewEnvLoader()}, nil
}
// func NewDisputeProceedingsLoggerDBInit() (DisputeProceedingsLoggerInterface,error) {
// DB, err := db.Init()
// if err != nil {
// return DisputeProceedingsLogger{}, err
// }
// return DisputeProceedingsLogger{DB: DB, EnvReader: env.NewEnvLoader()}, nil
// }

func NewDisputeProceedingsLogger(db *gorm.DB) DisputeProceedingsLogger {
return DisputeProceedingsLogger{DB: db, EnvReader: env.NewEnvLoader()}
func NewDisputeProceedingsLogger(db *gorm.DB, envLoader env.Env) DisputeProceedingsLoggerInterface {
return DisputeProceedingsLogger{DB: db, EnvReader: envLoader}
}

func (d DisputeProceedingsLogger) LogDisputeProceedings(proceedingType models.EventTypes, eventData map[string]interface{}) error {
Expand Down
40 changes: 29 additions & 11 deletions api/handlers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/gin-gonic/gin"
)


func SetupArchiveRoutes(g *gin.RouterGroup, h Archive) {
g.POST("/search", h.SearchArchive)
g.GET("/highlights", h.Highlights)
Expand All @@ -39,7 +38,7 @@ func (h Archive) Highlights(c *gin.Context) {

// Query the database
var disputes []models.Dispute
if err := h.DB.Model(&models.Dispute{}).Limit(limit).Scan(&disputes).Error; err != nil {
if err := h.DB.Model(&models.Dispute{}).Where("resolved = ?", true).Limit(limit).Scan(&disputes).Error; err != nil {
logger.WithError(err).Error("Error retrieving disputes")
c.JSON(http.StatusInternalServerError, models.Response{Error: "Error retrieving disputes"})
return
Expand All @@ -48,13 +47,19 @@ func (h Archive) Highlights(c *gin.Context) {
// Transform the results to ArchivedDisputeSummary
summaries := make([]models.ArchivedDisputeSummary, len(disputes))
for i, dispute := range disputes {
disputeSummary := models.DisputeSummaries{}
err := h.DB.Model(models.DisputeSummaries{}).Where("dispute = ?", *dispute.ID).First(&disputeSummary).Error
if err != nil {
logger.WithError(err).Error("Could not get dispute for id:" + fmt.Sprint(*dispute.ID))
}
summaries[i] = models.ArchivedDisputeSummary{
ID: *dispute.ID,
Title: dispute.Title,
Summary: dispute.Description,
Description: dispute.Description,
Summary: disputeSummary.Summary,
Category: []string{"Dispute"}, // Assuming a default category for now
DateFiled: dispute.CaseDate,
DateResolved: dispute.CaseDate.Add(48 * time.Hour), // Placeholder for resolved date
DateFiled: dispute.CaseDate.Format("2006-08-01"),
DateResolved: dispute.CaseDate.Add(48 * time.Hour).Format("2006-08-01"), // Placeholder for resolved date
Resolution: string(dispute.Decision),
}
}
Expand Down Expand Up @@ -151,13 +156,19 @@ func (h Archive) SearchArchive(c *gin.Context) {
// Transform the results to ArchivedDisputeSummary
var archiveDisputeSummaries []models.ArchivedDisputeSummary
for _, dispute := range disputes {
disputeSummary := models.DisputeSummaries{}
err := h.DB.Model(models.DisputeSummaries{}).Where("dispute = ?", *dispute.ID).First(&disputeSummary).Error
if err != nil {
logger.WithError(err).Error("Could not get dispute for id:" + fmt.Sprint(*dispute.ID))
}
archiveDisputeSummaries = append(archiveDisputeSummaries, models.ArchivedDisputeSummary{
ID: *dispute.ID,
Title: dispute.Title,
Summary: dispute.Description,
Description: dispute.Description,
Summary: disputeSummary.Summary,
Category: []string{"Dispute"}, // Assuming a default category for now
DateFiled: dispute.CaseDate,
DateResolved: dispute.CaseDate.Add(48 * time.Hour), // Placeholder for resolved date
DateFiled: dispute.CaseDate.Format("2006-08-01"),
DateResolved: dispute.CaseDate.Add(48 * time.Hour).Format("2006-08-01"), // Placeholder for resolved date
Resolution: string(dispute.Decision),
})
}
Expand Down Expand Up @@ -231,14 +242,21 @@ func (h Archive) getArchive(c *gin.Context) {
//transform to archive dispute
var archiveDispute models.ArchivedDispute
if *dispute.ID != 0 {
disputeSummary := models.DisputeSummaries{}
err := h.DB.Model(models.DisputeSummaries{}).Where("dispute = ?", *dispute.ID).First(&disputeSummary).Error
if err != nil {
logger.WithError(err).Error("Could not get dispute for id:" + fmt.Sprint(*dispute.ID))
}
archiveDispute = models.ArchivedDispute{

ArchivedDisputeSummary: models.ArchivedDisputeSummary{
ID: *dispute.ID,
Title: dispute.Title,
Summary: dispute.Description,
Description: dispute.Description,
Summary: disputeSummary.Summary,
Category: []string{"Dispute"}, // Assuming a default category for now
DateFiled: dispute.CaseDate,
DateResolved: dispute.CaseDate.Add(48 * time.Hour), // Placeholder for resolved date
DateFiled: dispute.CaseDate.Format("2006-08-01"),
DateResolved: dispute.CaseDate.Add(48 * time.Hour).Format("2006-08-01"), // Placeholder for resolved date
Resolution: string(dispute.Decision),
},
Events: []models.Event{},
Expand Down
86 changes: 75 additions & 11 deletions api/handlers/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"api/models"
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand All @@ -25,30 +26,92 @@ const (
mockDisputeCount = 10
)

type ArchiveTestSuite struct {
suite.Suite
type mockJwtModel struct {
throwErrors bool
}

type mockAuditLogger struct {
}

func (m *mockJwtModel) GenerateJWT(user models.User) (string, error) {
if m.throwErrors {
return "", errors.ErrUnsupported
}
return "mock", nil
}
func (m *mockJwtModel) StoreJWT(email string, jwt string) error {
if m.throwErrors {
return errors.ErrUnsupported
}
return nil
}
func (m *mockJwtModel) GetJWT(email string) (string, error) {
if m.throwErrors {
return "", errors.ErrUnsupported
}
return "", nil
}
func (m *mockJwtModel) JWTMiddleware(c *gin.Context) {}

func (m *mockJwtModel) GetClaims(c *gin.Context) (models.UserInfoJWT, error) {
if m.throwErrors {
return models.UserInfoJWT{}, errors.ErrUnsupported
}
return models.UserInfoJWT{
ID: 0,
FirstName: "",
Surname: "",
Birthdate: time.Now(),
Nationality: "",
Role: "",
Email: "",
PhoneNumber: new(string),
AddressID: new(int64),
Status: "",
Gender: "",
PreferredLanguage: new(string),
Timezone: new(string),
}, nil

mock sqlmock.Sqlmock
db *gorm.DB
router *gin.Engine
}

func TestArchive(t *testing.T) {
suite.Run(t, new(ArchiveTestSuite))
}

// mock model auditlogger
func (m *mockAuditLogger) LogDisputeProceedings(proceedingType models.EventTypes, eventData map[string]interface{}) error {
return nil
}

type ArchiveTestSuite struct {
suite.Suite

mock sqlmock.Sqlmock
db *gorm.DB
router *gin.Engine
auditlogger *mockAuditLogger
}

// Runs before every test to set up the DB and routers
func (suite *ArchiveTestSuite) SetupTest() {
mock, db, _ := mockDatabase()

handler := new (handlers.Archive)
suite.mock = mock
suite.db = db
suite.auditlogger = &mockAuditLogger{}

handler := handlers.Archive{
Handler: handlers.Handler{
DB: db,
DisputeProceedingsLogger: suite.auditlogger,
},
}
gin.SetMode("release")
router := gin.Default()
router.POST("/archive/search", handler.SearchArchive)

suite.mock = mock
suite.db = db
suite.router = router

}

func mockDatabase() (sqlmock.Sqlmock, *gorm.DB, error) {
Expand Down Expand Up @@ -126,6 +189,7 @@ func (suite *ArchiveTestSuite) TestBadRequestReturnsError() {
assert.NotEmpty(suite.T(), result.Error)
}


func (suite *ArchiveTestSuite) TestReturnsValidJSON() {
rows := initDisputeRows()
suite.mock.ExpectQuery("^SELECT count(.+) FROM \"?disputes\"?.*").WillReturnRows(initCountRow(mockDisputeCount))
Expand All @@ -142,8 +206,8 @@ func (suite *ArchiveTestSuite) TestReturnsValidJSON() {
suite.router.ServeHTTP(w, req)

// Assert properties
assert.Equal(suite.T(), http.StatusInternalServerError, w.Code)
assert.Equal(suite.T(), http.StatusOK, w.Code)

var result models.Response
assert.Error(suite.T(), json.Unmarshal(w.Body.Bytes(), &result))
assert.NoError(suite.T(), json.Unmarshal(w.Body.Bytes(), &result))
}
Loading

0 comments on commit 60cad5f

Please sign in to comment.