-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1234 from France-ioi/ask_hint_fixes
Handle DB errors during token unmarshalling correctly in itemGetHintToken & saveGrade
- Loading branch information
Showing
6 changed files
with
122 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package items | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/France-ioi/AlgoreaBackend/v2/app/database" | ||
"github.com/France-ioi/AlgoreaBackend/v2/app/payloadstest" | ||
"github.com/France-ioi/AlgoreaBackend/v2/app/token" | ||
"github.com/France-ioi/AlgoreaBackend/v2/app/tokentest" | ||
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput" | ||
) | ||
|
||
func Test_saveGradeRequestParsed_UnmarshalJSON(t *testing.T) { | ||
testoutput.SuppressIfPasses(t) | ||
|
||
db, mock := database.NewDBMock() | ||
defer func() { _ = db.Close() }() | ||
|
||
expectedError := errors.New("error") | ||
mock.ExpectQuery("^" + regexp.QuoteMeta("SELECT public_key "+ | ||
"FROM `platforms` JOIN items ON items.platform_id = platforms.id WHERE (items.id = ?) LIMIT 1") + "$"). | ||
WithArgs(901756573345831409).WillReturnError(expectedError) | ||
|
||
r := saveGradeRequestParsed{ | ||
store: database.NewDataStore(db), | ||
publicKey: tokentest.AlgoreaPlatformPublicKeyParsed, | ||
} | ||
assert.PanicsWithError(t, expectedError.Error(), func() { | ||
_ = r.UnmarshalJSON([]byte(fmt.Sprintf(`{"score_token": %q, "answer_token": %q}`, | ||
token.Generate(payloadstest.ScorePayloadFromGrader, tokentest.AlgoreaPlatformPrivateKeyParsed), | ||
token.Generate(payloadstest.AnswerPayloadFromAlgoreaPlatform, tokentest.AlgoreaPlatformPrivateKeyParsed), | ||
))) | ||
}) | ||
assert.NoError(t, mock.ExpectationsWereMet()) | ||
} |
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