mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
96 lines
3.0 KiB
Go
96 lines
3.0 KiB
Go
package e2e
|
|
|
|
// TestTranslationQueryFlow tests querying a translation from fixtures.
|
|
func (s *E2ETestSuite) TestTranslationQueryFlow() {
|
|
query := `
|
|
query GetTranslation($id: ID!) {
|
|
translation(id: $id) {
|
|
id
|
|
name
|
|
language
|
|
workId
|
|
content
|
|
}
|
|
}
|
|
`
|
|
variables := map[string]interface{}{"id": "1"}
|
|
|
|
resp := s.executeGraphQL(query, variables, "")
|
|
s.Require().NotNil(resp["data"])
|
|
s.Require().Nil(resp["errors"])
|
|
|
|
tr := resp["data"].(map[string]interface{})["translation"].(map[string]interface{})
|
|
s.Equal("1", tr["id"])
|
|
s.Equal("en", tr["language"])
|
|
s.Equal("1", tr["workId"])
|
|
s.NotEmpty(tr["content"].(string))
|
|
}
|
|
|
|
// TestTranslationsForWork tests listing translations for a work.
|
|
func (s *E2ETestSuite) TestTranslationsForWork() {
|
|
query := `query { translations(workId: "1", limit: 20, offset: 0) { id language name } }`
|
|
resp := s.executeGraphQL(query, nil, "")
|
|
s.Require().NotNil(resp["data"])
|
|
s.Require().Nil(resp["errors"])
|
|
|
|
trs := resp["data"].(map[string]interface{})["translations"].([]interface{})
|
|
s.GreaterOrEqual(len(trs), 2)
|
|
}
|
|
|
|
// TestContributorTranslationLifecycle tests that a contributor can create a work, add a translation,
|
|
// then delete their own translation.
|
|
func (s *E2ETestSuite) TestContributorTranslationLifecycle() {
|
|
contributorToken := s.GenerateToken("contributor")
|
|
|
|
createWork := `
|
|
mutation CreateWork($input: WorkInput!) {
|
|
createWork(input: $input) { id name language }
|
|
}
|
|
`
|
|
workVars := map[string]interface{}{
|
|
"input": map[string]interface{}{
|
|
"name": "Contributor Work",
|
|
"language": "en",
|
|
"content": "Contributor work content",
|
|
},
|
|
}
|
|
workResp := s.executeGraphQL(createWork, workVars, contributorToken)
|
|
s.Require().NotNil(workResp["data"])
|
|
s.Require().Nil(workResp["errors"])
|
|
work := workResp["data"].(map[string]interface{})["createWork"].(map[string]interface{})
|
|
workID := work["id"].(string)
|
|
s.NotEmpty(workID)
|
|
|
|
createTranslation := `
|
|
mutation CreateTranslation($input: TranslationInput!) {
|
|
createTranslation(input: $input) { id name language workId }
|
|
}
|
|
`
|
|
trVars := map[string]interface{}{
|
|
"input": map[string]interface{}{
|
|
"name": "Contributor Translation",
|
|
"language": "fr",
|
|
"content": "Bonjour",
|
|
"workId": workID,
|
|
},
|
|
}
|
|
trResp := s.executeGraphQL(createTranslation, trVars, contributorToken)
|
|
s.Require().NotNil(trResp["data"])
|
|
s.Require().Nil(trResp["errors"])
|
|
tr := trResp["data"].(map[string]interface{})["createTranslation"].(map[string]interface{})
|
|
translationID := tr["id"].(string)
|
|
s.NotEmpty(translationID)
|
|
s.Equal(workID, tr["workId"].(string))
|
|
|
|
deleteMutation := `mutation DeleteTranslation($id: ID!) { deleteTranslation(id: $id) }`
|
|
deleteVars := map[string]interface{}{"id": translationID}
|
|
deleteResp := s.executeGraphQL(deleteMutation, deleteVars, contributorToken)
|
|
s.Require().NotNil(deleteResp["data"])
|
|
s.Require().Nil(deleteResp["errors"])
|
|
s.True(deleteResp["data"].(map[string]interface{})["deleteTranslation"].(bool))
|
|
|
|
var count int64
|
|
s.DB.Table("translations").Where("id = ?", translationID).Count(&count)
|
|
s.Equal(int64(0), count)
|
|
}
|