tests/testthat/test-data-extractors.R

pre_cleaned <- list(list(href = "https://api.spotify.com/v1/me/tracks?offset=0&limit=1", 
                         items = structure(list(added_at = "2021-08-06T19:45:20Z", 
                                                track.artists = list(structure(list(href = "https://api.spotify.com/v1/artists/0iidQFemlPhkoHqFroz2my", 
                                                                                    id = "0iidQFemlPhkoHqFroz2my", name = "Delta Rae", 
                                                                                    type = "artist", uri = "spotify:artist:0iidQFemlPhkoHqFroz2my", 
                                                                                    external_urls.spotify = "https://open.spotify.com/artist/0iidQFemlPhkoHqFroz2my"), class = "data.frame", row.names = 1L)), 
                                                track.available_markets = list(c("AD", "AE", "AG", "AL", 
                                                                                 "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", 
                                                                                 "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", 
                                                                                 "BS", "BT", "BW", "BY", "BZ", "CA", "CH", "CI", "CL", 
                                                                                 "CM", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", 
                                                                                 "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", 
                                                                                 "FJ", "FM", "FR", "GA", "GB", "GD", "GE", "GH", "GM", 
                                                                                 "GN", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", 
                                                                                 "HT", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JM", 
                                                                                 "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", 
                                                                                 "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", 
                                                                                 "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", "MH", 
                                                                                 "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", 
                                                                                 "MX", "MY", "MZ", "NA", "NE", "NG", "NI", "NL", "NO", 
                                                                                 "NP", "NR", "NZ", "OM", "PA", "PE", "PG", "PH", "PK", 
                                                                                 "PL", "PS", "PT", "PW", "PY", "QA", "RO", "RS", "RU", 
                                                                                 "RW", "SA", "SB", "SC", "SE", "SG", "SI", "SK", "SL", 
                                                                                 "SM", "SN", "SR", "ST", "SV", "SZ", "TD", "TG", "TH", 
                                                                                 "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", 
                                                                                 "UG", "US", "UY", "UZ", "VC", "VN", "VU", "WS", "XK", 
                                                                                 "ZA", "ZM", "ZW")), track.disc_number = 1L, track.duration_ms = 284920L, 
                                                track.explicit = FALSE, track.href = "https://api.spotify.com/v1/tracks/1UmKAxmX38mKnwUC9N4RuJ", 
                                                track.id = "1UmKAxmX38mKnwUC9N4RuJ", track.is_local = FALSE, 
                                                track.name = "Holding on to Good", track.popularity = 23L, 
                                                track.preview_url = "https://p.scdn.co/mp3-preview/800be7dc3956c9207509ba10c8464963f4d8c019?cid=2eafa74d94a94de18bdf4d22151a33fc", 
                                                track.track_number = 1L, track.type = "track", track.uri = "spotify:track:1UmKAxmX38mKnwUC9N4RuJ", 
                                                track.album.album_type = "album", track.album.artists = list(
                                                  structure(list(href = "https://api.spotify.com/v1/artists/0iidQFemlPhkoHqFroz2my", 
                                                                 id = "0iidQFemlPhkoHqFroz2my", name = "Delta Rae", 
                                                                 type = "artist", uri = "spotify:artist:0iidQFemlPhkoHqFroz2my", 
                                                                 external_urls.spotify = "https://open.spotify.com/artist/0iidQFemlPhkoHqFroz2my"), class = "data.frame", row.names = 1L)), 
                                                track.album.available_markets = list(c("AD", "AE", "AG", 
                                                                                       "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", 
                                                                                       "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", 
                                                                                       "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CH", "CI", 
                                                                                       "CL", "CM", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", 
                                                                                       "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ES", 
                                                                                       "FI", "FJ", "FM", "FR", "GA", "GB", "GD", "GE", "GH", 
                                                                                       "GM", "GN", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", 
                                                                                       "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IS", "IT", 
                                                                                       "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", 
                                                                                       "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", 
                                                                                       "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", 
                                                                                       "MH", "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", 
                                                                                       "MW", "MX", "MY", "MZ", "NA", "NE", "NG", "NI", "NL", 
                                                                                       "NO", "NP", "NR", "NZ", "OM", "PA", "PE", "PG", "PH", 
                                                                                       "PK", "PL", "PS", "PT", "PW", "PY", "QA", "RO", "RS", 
                                                                                       "RU", "RW", "SA", "SB", "SC", "SE", "SG", "SI", "SK", 
                                                                                       "SL", "SM", "SN", "SR", "ST", "SV", "SZ", "TD", "TG", 
                                                                                       "TH", "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", 
                                                                                       "UA", "UG", "US", "UY", "UZ", "VC", "VN", "VU", "WS", 
                                                                                       "XK", "ZA", "ZM", "ZW")), track.album.href = "https://api.spotify.com/v1/albums/42NjSADnDs97o75bICIqs0", 
                                                track.album.id = "42NjSADnDs97o75bICIqs0", track.album.images = list(
                                                  structure(list(height = c(640L, 300L, 64L), url = c("https://i.scdn.co/image/ab67616d0000b27349aaf14f0936159764cd728a", 
                                                                                                      "https://i.scdn.co/image/ab67616d00001e0249aaf14f0936159764cd728a", 
                                                                                                      "https://i.scdn.co/image/ab67616d0000485149aaf14f0936159764cd728a"
                                                  ), width = c(640L, 300L, 64L)), class = "data.frame", row.names = c(NA, 
                                                                                                                      3L))), track.album.name = "Carry The Fire", track.album.release_date = "2012-06-19", 
                                                track.album.release_date_precision = "day", track.album.total_tracks = 16L, 
                                                track.album.type = "album", track.album.uri = "spotify:album:42NjSADnDs97o75bICIqs0", 
                                                track.album.external_urls.spotify = "https://open.spotify.com/album/42NjSADnDs97o75bICIqs0", 
                                                track.external_ids.isrc = "USWB11200989", track.external_urls.spotify = "https://open.spotify.com/track/1UmKAxmX38mKnwUC9N4RuJ"), class = "data.frame", row.names = 1L), 
                         limit = 1L, `next` = "https://api.spotify.com/v1/me/tracks?offset=1&limit=1", 
                         offset = 0L, previous = NULL, total = 529L))

post_cleaned <- structure(list(added_at = "2021-08-06T19:45:20Z", track.artists = list(
  structure(list(href = "https://api.spotify.com/v1/artists/0iidQFemlPhkoHqFroz2my", 
                 id = "0iidQFemlPhkoHqFroz2my", name = "Delta Rae", type = "artist", 
                 uri = "spotify:artist:0iidQFemlPhkoHqFroz2my", external_urls.spotify = "https://open.spotify.com/artist/0iidQFemlPhkoHqFroz2my"), class = "data.frame", row.names = 1L)), 
  track.available_markets = list(c("AD", "AE", "AG", "AL", 
                                   "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", "BE", 
                                   "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", "BS", "BT", 
                                   "BW", "BY", "BZ", "CA", "CH", "CI", "CL", "CM", "CO", "CR", 
                                   "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", 
                                   "EC", "EE", "EG", "ES", "FI", "FJ", "FM", "FR", "GA", "GB", 
                                   "GD", "GE", "GH", "GM", "GN", "GQ", "GR", "GT", "GW", "GY", 
                                   "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IS", 
                                   "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", 
                                   "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", 
                                   "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", "MH", "MK", 
                                   "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", "MX", "MY", 
                                   "MZ", "NA", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ", 
                                   "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PS", "PT", "PW", 
                                   "PY", "QA", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SE", 
                                   "SG", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SZ", 
                                   "TD", "TG", "TH", "TL", "TN", "TO", "TR", "TT", "TV", "TW", 
                                   "TZ", "UA", "UG", "US", "UY", "UZ", "VC", "VN", "VU", "WS", 
                                   "XK", "ZA", "ZM", "ZW")), track.disc_number = 1L, track.duration_ms = 284920L, 
  track.explicit = FALSE, track.href = "https://api.spotify.com/v1/tracks/1UmKAxmX38mKnwUC9N4RuJ", 
  track.id = "1UmKAxmX38mKnwUC9N4RuJ", track.is_local = FALSE, 
  track.name = "Holding on to Good", track.popularity = 23L, 
  track.preview_url = "https://p.scdn.co/mp3-preview/800be7dc3956c9207509ba10c8464963f4d8c019?cid=2eafa74d94a94de18bdf4d22151a33fc", 
  track.track_number = 1L, track.type = "track", track.uri = "spotify:track:1UmKAxmX38mKnwUC9N4RuJ", 
  track.album.album_type = "album", track.album.artists = list(
    structure(list(href = "https://api.spotify.com/v1/artists/0iidQFemlPhkoHqFroz2my", 
                   id = "0iidQFemlPhkoHqFroz2my", name = "Delta Rae", 
                   type = "artist", uri = "spotify:artist:0iidQFemlPhkoHqFroz2my", 
                   external_urls.spotify = "https://open.spotify.com/artist/0iidQFemlPhkoHqFroz2my"), class = "data.frame", row.names = 1L)), 
  track.album.available_markets = list(c("AD", "AE", "AG", 
                                         "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", 
                                         "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", "BS", 
                                         "BT", "BW", "BY", "BZ", "CA", "CH", "CI", "CL", "CM", "CO", 
                                         "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", 
                                         "DZ", "EC", "EE", "EG", "ES", "FI", "FJ", "FM", "FR", "GA", 
                                         "GB", "GD", "GE", "GH", "GM", "GN", "GQ", "GR", "GT", "GW", 
                                         "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", 
                                         "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", 
                                         "KN", "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", 
                                         "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", "MH", 
                                         "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", "MX", 
                                         "MY", "MZ", "NA", "NE", "NG", "NI", "NL", "NO", "NP", "NR", 
                                         "NZ", "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PS", "PT", 
                                         "PW", "PY", "QA", "RO", "RS", "RU", "RW", "SA", "SB", "SC", 
                                         "SE", "SG", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", 
                                         "SZ", "TD", "TG", "TH", "TL", "TN", "TO", "TR", "TT", "TV", 
                                         "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VC", "VN", "VU", 
                                         "WS", "XK", "ZA", "ZM", "ZW")), track.album.href = "https://api.spotify.com/v1/albums/42NjSADnDs97o75bICIqs0", 
  track.album.id = "42NjSADnDs97o75bICIqs0", track.album.images = list(
    structure(list(height = c(640L, 300L, 64L), url = c("https://i.scdn.co/image/ab67616d0000b27349aaf14f0936159764cd728a", 
                                                        "https://i.scdn.co/image/ab67616d00001e0249aaf14f0936159764cd728a", 
                                                        "https://i.scdn.co/image/ab67616d0000485149aaf14f0936159764cd728a"
    ), width = c(640L, 300L, 64L)), class = "data.frame", row.names = c(NA, 
                                                                        3L))), track.album.name = "Carry The Fire", track.album.release_date = "2012-06-19", 
  track.album.release_date_precision = "day", track.album.total_tracks = 16L, 
  track.album.type = "album", track.album.uri = "spotify:album:42NjSADnDs97o75bICIqs0", 
  track.album.external_urls.spotify = "https://open.spotify.com/album/42NjSADnDs97o75bICIqs0", 
  track.external_ids.isrc = "USWB11200989", track.external_urls.spotify = "https://open.spotify.com/track/1UmKAxmX38mKnwUC9N4RuJ"), row.names = c(NA, 
                                                                                                                                                  -1L), class = "data.frame")


dat_artist <- structure(list(href = "https://api.spotify.com/v1/artists/0iidQFemlPhkoHqFroz2my", 
                             id = "0iidQFemlPhkoHqFroz2my", name = "Delta Rae", type = "artist", 
                             uri = "spotify:artist:0iidQFemlPhkoHqFroz2my", external_urls.spotify = "https://open.spotify.com/artist/0iidQFemlPhkoHqFroz2my"), row.names = c(NA, 
                                                                                                                                                                             -1L), class = "data.frame")

test_that("get_data extracts correctly", {
  expect_equal(list_to_dataframe(pre_cleaned), post_cleaned)
})

#TODO, don't explicitely call the method here - add the class properly
test_that("get_artist_data extracts correctly", {
  expect_equal(extract_nested_data.spotty_track(post_cleaned), dat_artist)
})
condwanaland/spotty documentation built on Dec. 19, 2021, 6:01 p.m.