Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Run Tests
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run frontend tests
run: |
npm install --save-dev jest
npm test

- name: Run backend tests
run: |
go test ./... -v
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pids
*.pid
*.seed
*.pid.lock
coverage/
*.lcov
.nyc_output
.npm
*.tgz
.yarn-integrity
.env
.vscode/
.DS_Store
logs
*.log
*.exe
*.dll
*.so
*.dylib
*.test
*.out
bin/
build/
dist/
*.cov
vendor/
go.work
*.cache
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# algorhythm
# AlGoRhythm

AlGoRhythm is a Golang-based web application that tracks the user's top artists and top tracks of the month.

## Table of Contents
1. [Prerequisites](#Prerequisites)
2. [Getting Started](#Getting-Started)
3. [Testing](#Testing)

## Prerequisites
In order to properly run this, you will need the following tools installed and configured on your client machine:

- `go`
- `npm`
- Spotify developer account

Once you have your Spotify developer account, you will need to ensure that you have an app specific to run this project. Once created, take note of the client secret and client ID as you will need it later.

## Getting Started
Before running the command, you will need to create an `.env` file at the root directory. The file needs to have the following:

```
CLIENT_ID=""
CLIENT_SECRET=""
STATE=""
```

For `STATE`, this value is up to the user, but it is recommended to use an encrypted password.

Once you have followed the prerequisites and installed all the needed dependencies, simply run the following command: `go run main.go`. From there, your default browser should kick off the web application against `http://localhost:8080`.

## Running Program
To run the program, you have three options: GUI mode, interactive CLI, or command line arguments.

### Testing
There is frontend and backend testing for the web application. For the backend changes, simply run the following command at the root directory: `go test ./... -v`.

For the frontend changes, once you have npm properly configured with Jest, simply run the following command: `npm test`.
38 changes: 38 additions & 0 deletions authenticate/authenticate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package authenticate

import (
"fmt"
"os"

"github.com/joho/godotenv"
spotifyauth "github.com/zmb3/spotify/v2/auth"
)

var (
authenticator *spotifyauth.Authenticator
redirectURI = "http://127.0.0.1:8080/callback"
)

// SpotifyAuthenticate enables login with your unique client ID and secret, loading env variables from the specified file.
func SpotifyAuthenticate(envFile string) (*spotifyauth.Authenticator, error) {
err := godotenv.Load(envFile)
if err != nil {
return nil, fmt.Errorf("error loading %s file: %v", envFile, err)
}

clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")

if clientID == "" || clientSecret == "" {
return nil, fmt.Errorf("CLIENT_ID and CLIENT_SECRET must be set")
}

authenticator = spotifyauth.New(
spotifyauth.WithRedirectURL(redirectURI),
spotifyauth.WithScopes(spotifyauth.ScopeUserTopRead),
spotifyauth.WithClientID(clientID),
spotifyauth.WithClientSecret(clientSecret),
)

return authenticator, nil
}
32 changes: 32 additions & 0 deletions authenticate/authenticate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package authenticate

import (
"os"
"testing"

"github.com/joho/godotenv"
)

const (
envFile = "../.env"
testEnvFile = "test.env"
)

func TestSpotifyBadAuthenticate(t *testing.T) {
err := godotenv.Load(testEnvFile)
if err != nil {
t.Fatalf("Error loading test.env file: %v", err)
}

os.Setenv("CLIENT_ID", os.Getenv("CLIENT_ID"))
os.Setenv("CLIENT_SECRET", os.Getenv("CLIENT_SECRET"))

auth, err := SpotifyAuthenticate(testEnvFile)
if err != nil {
t.Fatalf("SpotifyAuthenticate returned error: %v", err)
}

if auth == nil {
t.Error("Expected authenticator, got nil")
}
}
2 changes: 2 additions & 0 deletions authenticate/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CLIENT_ID="bogus"
CLIENT_SECRET="bogus"
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module algorhythm

go 1.25.0

require (
github.com/gorilla/mux v1.8.1
github.com/joho/godotenv v1.5.1
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/zmb3/spotify/v2 v2.0.0
)

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading