Permalink
Browse files

Fix JSON rendering of track elements

  • Loading branch information...
1 parent d73b326 commit 796544e53eb35e9ebfbe838730de38af6f74d762 @ocharles ocharles committed Mar 1, 2013
Showing with 92 additions and 47 deletions.
  1. +14 −4 .gitignore
  2. +1 −1 src/MusicBrainz/API/JSON.hs
  3. +77 −42 test/suite/JSON.hs
View
@@ -1,5 +1,15 @@
-dist/
-Setup.hs
-log/
-*.hi
+/.hpc
+dist
+cabal-dev
*.o
+*.hi
+*.chi
+*.chs.h
+*.tix
+*.o-boot
+*.hi-boot
+*.p_o
+*.p_hi
+/*.html
+/test.cfg
+/test/suite/Tests
@@ -204,7 +204,7 @@ instance ToJSON (Revision a) where
instance ToJSON Track where
toJSON Track{..} = object [ "name" .= trackName
, "recording" .= trackRecording
- , "duration" .= trackDuration
+ , "length" .= trackDuration
, "artist-credit" .= trackArtistCredit
, "number" .= trackPosition
]
View
@@ -8,36 +8,19 @@ import Data.Monoid (mempty)
import MusicBrainz
import MusicBrainz.Data
import MusicBrainz.Data.ArtistCredit
+import MusicBrainz.Data.Edit
import MusicBrainz.Data.Editor
import Test.MusicBrainz
import MusicBrainz.API.JSON ()
tests :: [Test]
tests =
- [ testGroup "Release"
+ [ testGroup "ToJSON Release"
[ testCase "Full release" $ do
- editor <- entityRef <$> register Editor { editorName = "ocharles", editorPassword = "" }
- release <- autoEdit $ do
- a <- fmap coreRef . viewRevision =<< create editor
- ArtistTree
- { artistData = Artist { artistName = "Artist"
- , artistSortName = "Artist"
- , artistComment = ""
- , artistBeginDate = emptyDate
- , artistEndDate = emptyDate
- , artistGender = Nothing
- , artistCountry = Nothing
- , artistType = Nothing
- , artistEnded = False
- }
- , artistRelationships = mempty
- , artistAliases = mempty
- , artistIpiCodes = mempty
- , artistAnnotation = mempty
- }
-
- ac <- getRef [ ArtistCreditName a "Artist" "" ]
+ editor <- testEditor
+ r <- autoEdit $ do
+ ac <- testArtistCredit editor
rg <- fmap coreRef . viewRevision =<< create editor
ReleaseGroupTree
@@ -75,27 +58,19 @@ tests =
, countryName = "United Kingdom"
}
- viewRevision =<< create editor
- ReleaseTree
- { releaseData = Release { releaseName = "Release"
- , releaseComment = "Comment"
- , releaseArtistCredit = ac
- , releaseReleaseGroup = rg
- , releaseDate = (Just 2012, Just 2, Just 15) ^?! partialDate
- , releaseCountry = Just uk
- , releaseScript = Just latin
- , releasePackaging = Just digipak
- , releaseStatus = Just official
- , releaseBarcode = Just $ "0013964381993" ^?! barcode
- , releaseLanguage = Just english
- }
- , releaseAnnotation = mempty
- , releaseLabels = mempty
- , releaseMediums = mempty
- , releaseRelationships = mempty
- }
+ return Release { releaseName = "Release"
+ , releaseComment = "Comment"
+ , releaseArtistCredit = ac
+ , releaseReleaseGroup = rg
+ , releaseDate = (Just 2012, Just 2, Just 15) ^?! partialDate
+ , releaseCountry = Just uk
+ , releaseScript = Just latin
+ , releasePackaging = Just digipak
+ , releaseStatus = Just official
+ , releaseBarcode = Just $ "0013964381993" ^?! barcode
+ , releaseLanguage = Just english
+ }
- let r = coreData release
toJSON r @?=
object [ "name" .= releaseName r
, "comment" .= releaseComment r
@@ -110,4 +85,64 @@ tests =
, "language" .= releaseLanguage r
]
]
+
+ , testCase "ToJSON Track" $ do
+ editor <- testEditor
+ track <- autoEdit $ do
+ ac <- testArtistCredit editor
+ recording <- fmap coreRef . viewRevision =<< create editor
+ RecordingTree { recordingData = Recording { recordingName = "R"
+ , recordingComment = mempty
+ , recordingArtistCredit = ac
+ , recordingDuration = Just 12
+ }
+ , recordingRelationships = mempty
+ , recordingAnnotation = mempty
+ , recordingIsrcs = mempty
+ , recordingPuids = mempty
+ }
+ return Track { trackName = "Track name"
+ , trackRecording = recording
+ , trackDuration = Just 12345
+ , trackArtistCredit = ac
+ , trackPosition = "4"
+ }
+ toJSON track @?=
+ object [ "name" .= trackName track
+ , "artist-credit" .= trackArtistCredit track
+ , "length" .= trackDuration track
+ , "number" .= trackPosition track
+ , "recording" .= trackRecording track
+ ]
]
+
+--------------------------------------------------------------------------------
+testArtistRef :: Ref Editor -> EditM (Ref Artist)
+testArtistRef editor = fmap coreRef . viewRevision =<< create editor
+ ArtistTree
+ { artistData = Artist { artistName = "Artist"
+ , artistSortName = "Artist"
+ , artistComment = ""
+ , artistBeginDate = emptyDate
+ , artistEndDate = emptyDate
+ , artistGender = Nothing
+ , artistCountry = Nothing
+ , artistType = Nothing
+ , artistEnded = False
+ }
+ , artistRelationships = mempty
+ , artistAliases = mempty
+ , artistIpiCodes = mempty
+ , artistAnnotation = mempty
+ }
+
+
+testArtistCredit :: Ref Editor -> EditM (Ref ArtistCredit)
+testArtistCredit editor = do
+ a <- testArtistRef editor
+ getRef [ ArtistCreditName a "Artist" "" ]
+
+
+testEditor :: MusicBrainz (Ref Editor)
+testEditor = entityRef <$> register
+ Editor { editorName = "ocharles", editorPassword = "" }

0 comments on commit 796544e

Please sign in to comment.