$ curl -b admin_key=wrong_key localhost:3000/admin/test
Forbidden
$ curl -b admin_key=$ADMIN_KEY localhost:3000/admin/test
OK
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"
]
]
]
}
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"]}
A quick test of authentication flow:
npm startif applicable. Go to the homepage of the app.For testing with
curland other shell commands,$ source .envto get.envvars.For testing admin permissions:
For testing
ids.csvtext parsing only:$ curl -XPOST -b admin_key=$ADMIN_KEY localhost:3000/admin/load-idsshould respond with json of the ids.csv config data (as of d9c2b97).Test data and results for `ids.csv` parsing:
Expected result: (as of 8914637)
For testing
ids.csvdb 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 thePOST /admin/load-idsendpoint inadmin.tsand replace it with the following line / uncomment the following line:After changing the code, always recompile/let
npm run watchrecompile 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:Run
$ curl -XPOST -b admin_key=$ADMIN_KEY localhost:3000/admin/load-ids. The playlists collection should have these documents:And the users collection should have these documents:
Now replace the data in
ids.csvwith this:And request
POST /admin/load-idsagain. You can restart the server to get the db formatting to normalize (assuming this still uses nedb). The playlists collection should have these documents:And the users collection should have these documents: