Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useful tests #73

Open
Noam-Bendelac opened this issue Dec 31, 2020 · 0 comments
Open

Useful tests #73

Noam-Bendelac opened this issue Dec 31, 2020 · 0 comments

Comments

@Noam-Bendelac
Copy link
Collaborator

Noam-Bendelac commented Dec 31, 2020

A quick test of authentication flow:

  • Start the server and CRA npm start if applicable. Go to the homepage of the app.
  • Clear all cookies, including the app's cookies and Spotify's cookies. Refresh and the login page should appear. Click login and a Spotify page should prompt you to log in to Spotify. Do that and it should redirect to the app's homepage and you should be logged in.
  • Clear just the app's cookies but not Spotify cookies. Refresh and the login page should appear. Click login and you should see the app's homepage, not the Spotify login page.

For testing with curl and other shell commands, $ source .env to get .env vars.

For testing admin permissions:

$ curl -b admin_key=wrong_key localhost:3000/admin/test
Forbidden
$ curl -b admin_key=$ADMIN_KEY localhost:3000/admin/test
OK

For testing ids.csv text parsing only:

$ curl -XPOST -b admin_key=$ADMIN_KEY localhost:3000/admin/load-ids should respond with json of the ids.csv config data (as of d9c2b97).

Test data and results for `ids.csv` parsing:
playlistid1,hybrid,user1,user2,user3#comment
playlistid2,separate,#
playlistid3,situated,user1,user2,user3,user4,# comment
# playlistid,test,user1,user2,user3#this results in error, uncomment to test

Expected result: (as of 8914637)

{
  "byPlaylist": [
    {
      "playlistId": "playlistid1",
      "chatMode": "hybrid",
      "userIds": [
        "user1",
        "user2",
        "user3"
      ]
    },
    {
      "playlistId": "playlistid2",
      "chatMode": "separate",
      "userIds": []
    },
    {
      "playlistId": "playlistid3",
      "chatMode": "situated",
      "userIds": [
        "user1",
        "user2",
        "user3",
        "user4"
      ]
    }
  ],
  "byUser": [
    [
      "user1",
      [
        "playlistid1",
        "playlistid3"
      ]
    ],
    [
      "user2",
      [
        "playlistid1",
        "playlistid3"
      ]
    ],
    [
      "user3",
      [
        "playlistid1",
        "playlistid3"
      ]
    ],
    [
      "user4",
      [
        "playlistid3"
      ]
    ]
  ]
}

For testing ids.csv db functionality:

Test data and results:

Start with empty playlists and users DB collections (set vars in .env to new file names). Comment out the await initializePlaylist() line in the POST /admin/load-ids endpoint in admin.ts and replace it with the following line / uncomment the following line:

await initializePlaylist({ tracks: { items: [
  { track: { id: 'mock track' }, added_by: { id: 'mock user' } }
]}} as SpotifyApi.SinglePlaylistResponse, config)

After changing the code, always recompile/let npm run watch recompile and restart the server. After changing .env, always restart the server. Make sure to change the code and the env vars back to normal after testing.

Put this data in ids.csv:

playlistid1,hybrid,user1,user2,user3
playlistid2,separate
playlistid3,situated,user1,user2,user3,user4

Run $ curl -XPOST -b admin_key=$ADMIN_KEY localhost:3000/admin/load-ids. The playlists collection should have these documents:

{
  "_id":"playlistid1",
  "chatMode":"hybrid",
  "users":["user1","user2","user3"],
  ... // other initial fields, might change in the future
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}
{
  "_id":"playlistid2",
  "chatMode":"separate",
  "users":[],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}
{
  "_id":"playlistid3",
  "chatMode":"situated",
  "users":["user1","user2","user3","user4"],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}

And the users collection should have these documents:

{"_id":"user1","playlists":["playlistid1","playlistid3"]}
{"_id":"user2","playlists":["playlistid1","playlistid3"]}
{"_id":"user3","playlists":["playlistid1","playlistid3"]}
{"_id":"user4","playlists":["playlistid3"]}

Now replace the data in ids.csv with this:

# (user2 removed, user5 new, users 1,3,4 same)
playlistid1,situated,user1,user3#   already in db
playlistid2,hybrid,user3#           already in db
playlistid3,separate,user1,user4#   already in db
playlistid4,hybrid,user5#           new to db

And request POST /admin/load-ids again. You can restart the server to get the db formatting to normalize (assuming this still uses nedb). The playlists collection should have these documents:

{
  "_id":"playlistid1",
  "chatMode":"situated",
  "users":["user1","user3"],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
{
  "_id":"playlistid2",
  "chatMode":"hybrid",
  "users":["user3"],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}
{
  "_id":"playlistid3",
  "chatMode":"separate",
  "users":["user1","user4"],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}
{
  "_id":"playlistid4",
  "chatMode":"hybrid",
  "users":["user5"],
  ...
  "tracks":[{"id":"mock track","addedBy":"mock user", ...}]
}

And the users collection should have these documents:

{"_id":"user1","playlists":["playlistid1","playlistid3"]}
{"_id":"user2","playlists":[]}
{"_id":"user3","playlists":["playlistid1","playlistid2"]}
{"_id":"user4","playlists":["playlistid3"]}
{"_id":"user5","playlists":["playlistid4"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant