Skip to content

Commit

Permalink
[merge] pull request #9 from akrck02/dev
Browse files Browse the repository at this point in the history
v0.0.2
  • Loading branch information
akrck02 authored Mar 30, 2024
2 parents 10bb88e + bc1e754 commit 0727d81
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 55 deletions.
2 changes: 1 addition & 1 deletion services/device.go → services/device/device.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package services
package devicedal

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion services/project.go → services/project/project.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package services
package projectdal

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion services/role.go → services/role/role.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package services
package roledal

import (
"context"
Expand Down
1 change: 0 additions & 1 deletion services/role_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion services/team.go → services/team/team.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package services
package teamdal

import (
"context"
Expand Down
1 change: 0 additions & 1 deletion services/team_test.go

This file was deleted.

8 changes: 5 additions & 3 deletions services/user.go → services/user/user.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package services
package userdal

import (
"context"

"github.com/akrck02/valhalla-core-dal/configuration"
"github.com/akrck02/valhalla-core-dal/database"
devicedal "github.com/akrck02/valhalla-core-dal/services/device"
"github.com/akrck02/valhalla-core-sdk/error"
"github.com/akrck02/valhalla-core-sdk/http"
"github.com/akrck02/valhalla-core-sdk/log"
"github.com/akrck02/valhalla-core-sdk/models"
"github.com/akrck02/valhalla-core-sdk/utils"

"github.com/golang-jwt/jwt/v5"

"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -138,7 +140,7 @@ func Login(conn context.Context, client *mongo.Client, user *models.User, ip str
}

device := &models.Device{Address: ip, UserAgent: address}
token, err := AddUserDevice(conn, client, found, device)
token, err := devicedal.AddUserDevice(conn, client, found, device)

if err != nil {
return "", &models.Error{
Expand Down Expand Up @@ -173,7 +175,7 @@ func LoginAuth(conn context.Context, client *mongo.Client, auth *models.AuthLogi
}

var devices = client.Database(database.CurrentDatabase).Collection(database.DEVICE)
device, deviceFindingError := FindDeviceByAuthToken(conn, devices, &filter)
device, deviceFindingError := devicedal.FindDeviceByAuthToken(conn, devices, &filter)

if deviceFindingError != nil || device == nil {
return &models.Error{
Expand Down
24 changes: 13 additions & 11 deletions services/device_test.go → tests/device_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package services
package tests

import (
"log"
"testing"

"github.com/akrck02/valhalla-core-dal/database"
"github.com/akrck02/valhalla-core-dal/mock"
devicedal "github.com/akrck02/valhalla-core-dal/services/device"
userdal "github.com/akrck02/valhalla-core-dal/services/user"
"github.com/akrck02/valhalla-core-sdk/models"
)

Expand All @@ -23,7 +25,7 @@ func TestDeviceExists(t *testing.T) {
Password: mock.Password(),
}

err := Register(conn, client, &user)
err := userdal.Register(conn, client, &user)

if err != nil {
t.Error(err)
Expand All @@ -37,15 +39,15 @@ func TestDeviceExists(t *testing.T) {
UserAgent: mock.Platform(),
}

_, error := AddUserDevice(conn, client, &user, &expected)
_, error := devicedal.AddUserDevice(conn, client, &user, &expected)

if error != nil {
t.Error(err)
}

// check if device exists
coll := client.Database(database.CurrentDatabase).Collection(database.DEVICE)
obtained, error := FindDevice(conn, coll, &expected)
obtained, error := devicedal.FindDevice(conn, coll, &expected)

if error != nil {
t.Error(err)
Expand All @@ -59,14 +61,14 @@ func TestDeviceExists(t *testing.T) {
log.Print("Device found: ", obtained)

// delete device
error = DeleteDevice(conn, client, &expected)
error = devicedal.DeleteDevice(conn, client, &expected)

if error != nil {
t.Error(err)
}

// delete user
err = DeleteUser(conn, client, &user)
err = userdal.DeleteUser(conn, client, &user)

if err != nil {
t.Error(err)
Expand All @@ -88,7 +90,7 @@ func TestDeviceNotExists(t *testing.T) {
Password: mock.Password(),
}

err := Register(conn, client, &user)
err := userdal.Register(conn, client, &user)

if err != nil {
t.Error(err)
Expand All @@ -102,15 +104,15 @@ func TestDeviceNotExists(t *testing.T) {
UserAgent: mock.Platform(),
}

_, error := AddUserDevice(conn, client, &user, &expected)
_, error := devicedal.AddUserDevice(conn, client, &user, &expected)

if error != nil {
t.Error(err)
}

// check if device exists
coll := client.Database(database.CurrentDatabase).Collection(database.DEVICE)
obtained, error := FindDevice(conn, coll, &models.Device{
obtained, error := devicedal.FindDevice(conn, coll, &models.Device{
Token: mock.Token(),
})

Expand All @@ -122,14 +124,14 @@ func TestDeviceNotExists(t *testing.T) {
log.Print("Device not found: ", obtained)

// delete device
error = DeleteDevice(conn, client, &expected)
error = devicedal.DeleteDevice(conn, client, &expected)

if error != nil {
t.Error(err)
}

// delete user
err = DeleteUser(conn, client, &user)
err = userdal.DeleteUser(conn, client, &user)

if err != nil {
t.Error(err)
Expand Down
5 changes: 3 additions & 2 deletions services/project_test.go → tests/project_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package services
package tests

import (
"testing"

"github.com/akrck02/valhalla-api-common/http"
"github.com/akrck02/valhalla-core-dal/database"
"github.com/akrck02/valhalla-core-dal/mock"
projectdal "github.com/akrck02/valhalla-core-dal/services/project"
"github.com/akrck02/valhalla-core-sdk/error"
"github.com/akrck02/valhalla-core-sdk/models"
)
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestGetUserProjects(t *testing.T) {
project := CreateMockTestProjectWithUser(t, conn, client, user)
project2 := CreateMockTestProjectWithUser(t, conn, client, user)

projects := GetUserProjects(conn, client, user.Email)
projects := projectdal.GetUserProjects(conn, client, user.Email)

if len(projects) == 0 {
t.Errorf("No projects found for user: %v", user.Email)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package services
package tests

import (
"context"
"testing"

"github.com/akrck02/valhalla-core-dal/mock"
projectdal "github.com/akrck02/valhalla-core-dal/services/project"
"github.com/akrck02/valhalla-core-sdk/log"
"github.com/akrck02/valhalla-core-sdk/models"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -39,7 +40,7 @@ func CreateMockTestProjectWithUser(t *testing.T, conn context.Context, client *m
func CreateTestProjectWithUser(t *testing.T, conn context.Context, client *mongo.Client, project *models.Project, user *models.User) *models.Project {

log.FormattedInfo("Creating project: ${0}", project.Name)
err := CreateProject(conn, client, project)
err := projectdal.CreateProject(conn, client, project)

if err != nil {
t.Errorf("Error creating project: %v", err)
Expand All @@ -58,7 +59,7 @@ func CreateTestProjectWithUser(t *testing.T, conn context.Context, client *mongo
func CreateTestProjectWithError(t *testing.T, conn context.Context, client *mongo.Client, project *models.Project, status int, errorcode int) {

log.FormattedInfo("Creating project: ${0}", project.Name)
err := CreateProject(conn, client, project)
err := projectdal.CreateProject(conn, client, project)

if err == nil {
t.Error("Project created successfully")
Expand All @@ -83,7 +84,7 @@ func CreateTestProjectWithError(t *testing.T, conn context.Context, client *mong
func DeleteTestProject(t *testing.T, conn context.Context, client *mongo.Client, project *models.Project) {

log.FormattedInfo("Deleting project: ${0}", project.Name)
err := DeleteProject(conn, client, project)
err := projectdal.DeleteProject(conn, client, project)

if err != nil {
t.Errorf("Error deleting project: %v", err)
Expand Down
1 change: 1 addition & 0 deletions tests/role_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package tests
1 change: 1 addition & 0 deletions tests/team_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package tests
25 changes: 13 additions & 12 deletions services/user_test.go → tests/user_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package services
package tests

import (
"testing"

"github.com/akrck02/valhalla-core-dal/database"
userdal "github.com/akrck02/valhalla-core-dal/services/user"
"github.com/akrck02/valhalla-core-sdk/error"
"github.com/akrck02/valhalla-core-sdk/http"
"github.com/akrck02/valhalla-core-sdk/log"
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestLoginWrongEmail(t *testing.T) {
LoginTestUserWithError(t, conn, client, user, mock.Ip(), mock.Platform(), http.HTTP_STATUS_FORBIDDEN, error.USER_NOT_AUTHORIZED)

user.Email = realEmail
DeleteUser(conn, client, user)
userdal.DeleteUser(conn, client, user)
}

func TestLoginAuth(t *testing.T) {
Expand Down Expand Up @@ -295,7 +296,7 @@ func TestEditUserEmail(t *testing.T) {

// Change the user email
log.Info("Changing user email")
emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand All @@ -313,7 +314,7 @@ func TestEditUserEmailNoEmail(t *testing.T) {
conn := database.Connect(*client)
defer database.Disconnect(*client, conn)

emailChangeRequest := EmailChangeRequest{}
emailChangeRequest := userdal.EmailChangeRequest{}
EditTestUserEmailWithError(t, conn, client, &emailChangeRequest, http.HTTP_STATUS_BAD_REQUEST, error.EMPTY_EMAIL)

}
Expand All @@ -327,7 +328,7 @@ func TestEditUserEmailNoDotEmail(t *testing.T) {
email := mock.Email()
newEmail := mock.EmailNotDot()

emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand All @@ -345,7 +346,7 @@ func TestEditUserEmailNoAtEmail(t *testing.T) {
email := mock.Email()
newEmail := mock.EmailNotAt()

emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand All @@ -363,7 +364,7 @@ func TestEditUserEmailShortEmail(t *testing.T) {
email := mock.Email()
newEmail := mock.EmailShort()

emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand All @@ -381,7 +382,7 @@ func TestEditUserEmailNotFound(t *testing.T) {
email := mock.Email()
newEmail := "xXx" + mock.Email()

emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand Down Expand Up @@ -419,7 +420,7 @@ func TestEditUserEmailExists(t *testing.T) {
log.Jump()

// Change the email
emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: newEmail,
}
Expand All @@ -439,7 +440,7 @@ func TestEditUserSameEmail(t *testing.T) {
defer database.Disconnect(*client, conn)

email := mock.Email()
emailChangeRequest := EmailChangeRequest{
emailChangeRequest := userdal.EmailChangeRequest{
Email: email,
NewEmail: email,
}
Expand Down Expand Up @@ -631,15 +632,15 @@ func TestValidationCode(t *testing.T) {
user := RegisterMockTestUser(t, conn, client)

// get the user
user, err := GetUser(conn, client, user, true)
user, err := userdal.GetUser(conn, client, user, true)

if err != nil {
t.Error("The user was not found", err)
return
}

// validate the user
err = ValidateUser(conn, client, user.ValidationCode)
err = userdal.ValidateUser(conn, client, user.ValidationCode)

if err != nil {
t.Error("The user was not validated", err)
Expand Down
Loading

0 comments on commit 0727d81

Please sign in to comment.