Skip to content

Commit

Permalink
Add interface to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Jul 15, 2024
1 parent 91c058d commit 3424e11
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 380 deletions.
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# No double quote needed for the text. Database will fail.
PG_HOST=localhost
PG_USER=your_db_user
PG_PASSWORD=your_db_password
Expand Down
Binary file added backend/backend
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied.

CREATE TABLE users
CREATE TABLE IF NOT EXISTS users
(
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE cardgroups
CREATE TABLE IF NOT EXISTS cardgroups
(
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE cards
CREATE TABLE IF NOT EXISTS cards
(
id BIGSERIAL PRIMARY KEY,
front TEXT NOT NULL,
Expand All @@ -28,31 +28,31 @@ CREATE TABLE cards
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
cardgroup_id INTEGER NOT NULL,
FOREIGN KEY (cardgroup_id) REFERENCES cardgroups (id) ON DELETE CASCADE
);
);

CREATE TABLE cardgroup_users
CREATE TABLE IF NOT EXISTS cardgroup_users
(
cardgroup_id BIGINT NOT NULL,
user_id BIGINT NOT NULL,
PRIMARY KEY (cardgroup_id, user_id),
FOREIGN KEY (cardgroup_id) REFERENCES cardgroups (id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
);

CREATE TABLE roles
CREATE TABLE IF NOT EXISTS roles
(
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);

CREATE TABLE user_roles
CREATE TABLE IF NOT EXISTS user_roles
(
user_id BIGINT NOT NULL,
role_id BIGINT NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE
);
);

-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back.
Expand Down
7 changes: 6 additions & 1 deletion backend/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestMain(m *testing.M) {
}

// Setup Echo server
db = pg.DB
db = pg.GetDB()
e = setupEchoServer(db)

// Run the tests
Expand Down Expand Up @@ -125,6 +125,7 @@ func removeField(data map[string]interface{}, field string) {
}

func runServersTest(t *testing.T, fn func(*testing.T)) {

// Begin a new transaction
tx := db.Begin()
if tx.Error != nil {
Expand Down Expand Up @@ -170,6 +171,8 @@ func runServersTest(t *testing.T, fn func(*testing.T)) {
}

func TestMutationResolver(t *testing.T) {
t.Helper()

runServersTest(t, func(t *testing.T) {
t.Run("CreateCard", func(t *testing.T) {

Expand Down Expand Up @@ -416,6 +419,8 @@ func TestMutationResolver(t *testing.T) {
}

func TestQueryResolver(t *testing.T) {
t.Helper()

runServersTest(t, func(t *testing.T) {
t.Run("Cards", func(t *testing.T) {

Expand Down
21 changes: 8 additions & 13 deletions backend/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/labstack/echo/v4/middleware"
"net/http"
"net/http/httptest"
"os"
"testing"

"backend/pkg/config"
Expand All @@ -20,13 +19,9 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
// Set up the test environment
code := m.Run()
os.Exit(code)
}
func TestMainSmoke(t *testing.T) {
t.Parallel()

func TestGraphQLServer(t *testing.T) {
ctx := context.Background()
user := "test"
password := "test"
Expand All @@ -45,11 +40,11 @@ func TestGraphQLServer(t *testing.T) {
}

// Override the config values for testing
config.Cfg.PGHost = pg.Config.Host
config.Cfg.PGUser = pg.Config.User
config.Cfg.PGPassword = pg.Config.Password
config.Cfg.PGDBName = pg.Config.DBName
config.Cfg.PGPort = pg.Config.Port
config.Cfg.PGHost = pg.GetConfig().Host
config.Cfg.PGUser = pg.GetConfig().User
config.Cfg.PGPassword = pg.GetConfig().Password
config.Cfg.PGDBName = pg.GetConfig().DBName
config.Cfg.PGPort = pg.GetConfig().Port
config.Cfg.PGSSLMode = "disable"
config.Cfg.Port = 8080

Expand All @@ -60,7 +55,7 @@ func TestGraphQLServer(t *testing.T) {

// Create a new resolver with the database connection
resolver := &graph.Resolver{
DB: pg.DB,
DB: pg.GetDB(),
}

srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: resolver}))
Expand Down
50 changes: 0 additions & 50 deletions backend/pkg/flashcard/flashcard_system.go

This file was deleted.

Loading

0 comments on commit 3424e11

Please sign in to comment.