|
|
|
@ -123,8 +123,8 @@ function transformActionIDs(action: DBAction, mappings: IDMappings, rng: any) { |
|
|
|
|
case DBActionType.PatchTrack: |
|
|
|
|
{ |
|
|
|
|
let track = r.payload as TrackWithRefsWithId; |
|
|
|
|
track.tagIds && track.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
track.artistIds && track.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
track.tagIds && track.tagIds.forEach((id: number, idx: number) => track.tagIds[idx] = doMap(id, mappings.tags)); |
|
|
|
|
track.artistIds && track.artistIds.forEach((id: number, idx: number) => track.artistIds[idx] = doMap(id, mappings.artists)); |
|
|
|
|
if (track.albumId) { track.albumId = doMap(track.albumId, mappings.albums); } |
|
|
|
|
if (track.id) { track.id = doMap(track.id, mappings.tracks); } |
|
|
|
|
break; |
|
|
|
@ -134,9 +134,9 @@ function transformActionIDs(action: DBAction, mappings: IDMappings, rng: any) { |
|
|
|
|
case DBActionType.PatchArtist: |
|
|
|
|
{ |
|
|
|
|
let artist = r.payload as ArtistWithRefsWithId; |
|
|
|
|
artist.tagIds && artist.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
artist.albumIds && artist.albumIds.forEach((id: number) => doMap(id, mappings.albums)); |
|
|
|
|
artist.trackIds && artist.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
artist.tagIds && artist.tagIds.forEach((id: number, idx: number) => artist.tagIds[idx] = doMap(id, mappings.tags)); |
|
|
|
|
artist.albumIds && artist.albumIds.forEach((id: number, idx: number) => artist.albumIds[idx] = doMap(id, mappings.albums)); |
|
|
|
|
artist.trackIds && artist.trackIds.forEach((id: number, idx: number) => artist.trackIds[idx] = doMap(id, mappings.tracks)); |
|
|
|
|
if (artist.id) { artist.id = doMap(artist.id, mappings.artists); } |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -145,10 +145,12 @@ function transformActionIDs(action: DBAction, mappings: IDMappings, rng: any) { |
|
|
|
|
case DBActionType.PatchAlbum: |
|
|
|
|
{ |
|
|
|
|
let album = r.payload as AlbumWithRefsWithId; |
|
|
|
|
album.tagIds && album.tagIds.forEach((id: number) => doMap(id, mappings.tags)); |
|
|
|
|
album.artistIds && album.artistIds.forEach((id: number) => doMap(id, mappings.artists)); |
|
|
|
|
album.trackIds && album.trackIds.forEach((id: number) => doMap(id, mappings.tracks)); |
|
|
|
|
console.log(`album trackIds before: ${JSON.stringify(album.trackIds)}`) |
|
|
|
|
album.tagIds && album.tagIds.forEach((id: number, idx: number) => album.tagIds[idx] = doMap(id, mappings.tags)); |
|
|
|
|
album.artistIds && album.artistIds.forEach((id: number, idx: number) => album.artistIds[idx] = doMap(id, mappings.artists)); |
|
|
|
|
album.trackIds && album.trackIds.forEach((id: number, idx: number) => album.trackIds[idx] = doMap(id, mappings.tracks)); |
|
|
|
|
if (album.id) { album.id = doMap(album.id, mappings.albums); } |
|
|
|
|
console.log(`album trackIds after: ${JSON.stringify(album.trackIds)}`) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.CreateTag: |
|
|
|
@ -174,6 +176,12 @@ function transformActionIDs(action: DBAction, mappings: IDMappings, rng: any) { |
|
|
|
|
r.payload = (mappings as any)[keys[r.type]][r.payload]; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case DBActionType.MergeTag: |
|
|
|
|
{ |
|
|
|
|
r.payload.fromId = doMap(r.payload.fromId, mappings.tags); |
|
|
|
|
r.payload.toId = doMap(r.payload.toId, mappings.tags); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
@ -234,22 +242,23 @@ describe('Randomized model-based DB back-end tests', () => { |
|
|
|
|
// be generated.
|
|
|
|
|
let dist: RandomDBActionDistribution = { |
|
|
|
|
type: new Map([ |
|
|
|
|
[DBActionType.CreateTrack, 0.0625], |
|
|
|
|
[DBActionType.CreateArtist, 0.0625], |
|
|
|
|
[DBActionType.CreateAlbum, 0.0625], |
|
|
|
|
[DBActionType.CreateTag, 0.0625], |
|
|
|
|
[DBActionType.PutTrack, 0.0625], |
|
|
|
|
[DBActionType.PutArtist, 0.0625], |
|
|
|
|
[DBActionType.PutAlbum, 0.0625], |
|
|
|
|
[DBActionType.PutTag, 0.0625], |
|
|
|
|
[DBActionType.PatchTrack, 0.0625], |
|
|
|
|
[DBActionType.PatchArtist, 0.0625], |
|
|
|
|
[DBActionType.PatchAlbum, 0.0625], |
|
|
|
|
[DBActionType.PatchTag, 0.0625], |
|
|
|
|
[DBActionType.DeleteTrack, 0.0625], |
|
|
|
|
[DBActionType.DeleteArtist, 0.0625], |
|
|
|
|
[DBActionType.DeleteAlbum, 0.0625], |
|
|
|
|
[DBActionType.DeleteTag, 0.0625], |
|
|
|
|
[DBActionType.CreateTrack, 0.05883], |
|
|
|
|
[DBActionType.CreateArtist, 0.05883], |
|
|
|
|
[DBActionType.CreateAlbum, 0.05883], |
|
|
|
|
[DBActionType.CreateTag, 0.05883], |
|
|
|
|
[DBActionType.PutTrack, 0.05883], |
|
|
|
|
[DBActionType.PutArtist, 0.05883], |
|
|
|
|
[DBActionType.PutAlbum, 0.05883], |
|
|
|
|
[DBActionType.PutTag, 0.05883], |
|
|
|
|
[DBActionType.PatchTrack, 0.05883], |
|
|
|
|
[DBActionType.PatchArtist, 0.05883], |
|
|
|
|
[DBActionType.PatchAlbum, 0.05883], |
|
|
|
|
[DBActionType.PatchTag, 0.05883], |
|
|
|
|
[DBActionType.DeleteTrack, 0.05883], |
|
|
|
|
[DBActionType.DeleteArtist, 0.05883], |
|
|
|
|
[DBActionType.DeleteAlbum, 0.05883], |
|
|
|
|
[DBActionType.DeleteTag, 0.05883], |
|
|
|
|
[DBActionType.MergeTag, 0.05883], |
|
|
|
|
]), |
|
|
|
|
userId: new Map([[1, 1.0]]), |
|
|
|
|
createTrackParams: { |
|
|
|
@ -413,6 +422,10 @@ describe('Randomized model-based DB back-end tests', () => { |
|
|
|
|
deleteTagParams: { |
|
|
|
|
validId: new Map([[false, 0.2], [true, 0.8]]) |
|
|
|
|
}, |
|
|
|
|
mergeTagParams: { |
|
|
|
|
validFromId: new Map([[false, 0.2], [true, 0.8]]), |
|
|
|
|
validToId: new Map([[false, 0.2], [true, 0.8]]), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Loop to generate and execute a bunch of random actions.
|
|
|
|
|