This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1903 from graphcool/backwards-compatible-migratio…
…n-steps-for-relations Backwards compatible parsing of Relation Migration Steps
- Loading branch information
Showing
3 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ared-models/src/test/scala/com/prisma/shared/models/MigrationStepsJsonFormatterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.prisma.shared.models | ||
|
||
import org.scalatest.{FlatSpec, Matchers} | ||
import play.api.libs.json.Json | ||
|
||
class MigrationStepsJsonFormatterSpec extends FlatSpec with Matchers { | ||
|
||
import MigrationStepsJsonFormatter._ | ||
|
||
"CreateRelation" should "be readable in the format of January 2018" in { | ||
val json = Json.parse(""" | ||
|{ | ||
| "name": "ListToTodo", | ||
| "leftModelName": "List", | ||
| "rightModelName": "Todo", | ||
| "discriminator": "CreateRelation" | ||
| } | ||
""".stripMargin) | ||
|
||
val create = json.as[CreateRelation] | ||
create.name should equal("ListToTodo") | ||
create.modelAName should equal("List") | ||
create.modelBName should equal("Todo") | ||
create.modelAOnDelete should equal(OnDelete.SetNull) | ||
create.modelBOnDelete should equal(OnDelete.SetNull) | ||
} | ||
|
||
"CreateRelation" should "be readable in the format of February 2018" in { | ||
val json = Json.parse(""" | ||
|{ | ||
| "name": "ListToTodo", | ||
| "leftModelName": "List", | ||
| "rightModelName": "Todo", | ||
| "modelAOnDelete": "CASCADE", | ||
| "modelBOnDelete": "SET_NULL", | ||
| "discriminator": "CreateRelation" | ||
| } | ||
""".stripMargin) | ||
|
||
val create = json.as[CreateRelation] | ||
create.name should equal("ListToTodo") | ||
create.modelAName should equal("List") | ||
create.modelBName should equal("Todo") | ||
create.modelAOnDelete should equal(OnDelete.Cascade) | ||
create.modelBOnDelete should equal(OnDelete.SetNull) | ||
} | ||
|
||
"CreateRelation" should "be readable in the BROKEN format of February 2018" in { | ||
val json = Json.parse(""" | ||
|{ | ||
| "name": "ListToTodo", | ||
| "modelAName": "List", | ||
| "modelBName": "Todo", | ||
| "modelAOnDelete": "CASCADE", | ||
| "modelBOnDelete": "SET_NULL", | ||
| "discriminator": "CreateRelation" | ||
| } | ||
""".stripMargin) | ||
|
||
val create = json.as[CreateRelation] | ||
create.name should equal("ListToTodo") | ||
create.modelAName should equal("List") | ||
create.modelBName should equal("Todo") | ||
create.modelAOnDelete should equal(OnDelete.Cascade) | ||
create.modelBOnDelete should equal(OnDelete.SetNull) | ||
} | ||
|
||
"UpdateRelation" should "be readable in the format of January 2018" in { | ||
val json = Json.parse(""" | ||
|{ | ||
| "name": "ListToTodo", | ||
| "newName": "ListToTodoNew", | ||
| "modelAId": "List", | ||
| "modelBId": "Todo", | ||
| "discriminator": "UpdateRelation" | ||
| } | ||
""".stripMargin) | ||
|
||
val create = json.as[UpdateRelation] | ||
create.name should equal("ListToTodo") | ||
create.newName should equal(Some("ListToTodoNew")) | ||
create.modelAId should equal(Some("List")) | ||
create.modelBId should equal(Some("Todo")) | ||
create.modelAOnDelete should equal(None) | ||
create.modelBOnDelete should equal(None) | ||
} | ||
|
||
"UpdateRelation" should "be readable in the format of February 2018" in { | ||
val json = Json.parse(""" | ||
|{ | ||
| "name": "ListToTodo", | ||
| "newName": "ListToTodoNew", | ||
| "modelAId": "List", | ||
| "modelBId": "Todo", | ||
| "modelAOnDelete": "CASCADE", | ||
| "modelBOnDelete": "SET_NULL", | ||
| "discriminator": "UpdateRelation" | ||
| } | ||
""".stripMargin) | ||
|
||
val create = json.as[UpdateRelation] | ||
create.name should equal("ListToTodo") | ||
create.newName should equal(Some("ListToTodoNew")) | ||
create.modelAId should equal(Some("List")) | ||
create.modelBId should equal(Some("Todo")) | ||
create.modelAOnDelete should equal(Some(OnDelete.Cascade)) | ||
create.modelBOnDelete should equal(Some(OnDelete.SetNull)) | ||
} | ||
} |