PlotDirector/PlotLine.Tests/Sql/NativeChapterReviewRegression.sql

21 lines
1.9 KiB
Transact-SQL

IF DB_NAME()<>N'PlotDirector_Development' THROW 51000,'Wrong database',1;
BEGIN TRANSACTION;
BEGIN TRY
DECLARE @ID uniqueidentifier=NEWID(),@Other uniqueidentifier=NEWID(),@Doc uniqueidentifier=NEWID();
EXEC dbo.NativeChapterReview_Access @Action='Save',@UserID=2147483646,@BookID=2147483646,@ReviewID=@ID,@ManuscriptID=@Doc,@ChapterStart=10,@ChapterEnd=20,@ContentHash='synthetic-native-review-regression',@ResultJson=N'{"State":"complete","Scenes":[]}';
EXEC dbo.NativeChapterReview_Access @Action='Save',@UserID=2147483646,@BookID=2147483646,@ReviewID=@Other,@ManuscriptID=@Doc,@ChapterStart=10,@ChapterEnd=20,@ContentHash='synthetic-native-review-regression',@ResultJson=N'{"State":"complete","Scenes":[]}';
IF (SELECT COUNT(*) FROM dbo.NativeChapterReviews WHERE UserID=2147483646 AND ManuscriptID=@Doc)<>1 THROW 51000,'Duplicate content created multiple reviews',1;
EXEC dbo.NativeChapterReview_Access @Action='Decide',@UserID=2147483646,@ReviewID=@ID,@Version=1,@DecisionsJson=N'[{"State":"approved"}]';
IF NOT EXISTS(SELECT 1 FROM dbo.NativeChapterReviews WHERE ReviewID=@ID AND Version=2) THROW 51000,'Decision version not incremented',1;
EXEC dbo.NativeChapterReview_Access @Action='Decide',@UserID=2147483646,@ReviewID=@ID,@Version=1,@DecisionsJson=N'[{"State":"rejected"}]';
IF NOT EXISTS(SELECT 1 FROM dbo.NativeChapterReviews WHERE ReviewID=@ID AND DecisionsJson=N'[{"State":"approved"}]') THROW 51000,'Stale decision overwrote review',1;
EXEC dbo.NativeChapterReview_Access @Action='Decide',@UserID=2147483645,@ReviewID=@ID,@Version=2,@DecisionsJson=N'[]';
IF NOT EXISTS(SELECT 1 FROM dbo.NativeChapterReviews WHERE ReviewID=@ID AND Version=2) THROW 51000,'Other user changed review',1;
ROLLBACK;
SELECT 'PASS synthetic Development review persistence, content idempotency, optimistic decisions and user scope; fixture rolled back';
END TRY
BEGIN CATCH
IF @@TRANCOUNT>0 ROLLBACK;
THROW;
END CATCH;