Home Reference Source Test

test/1_unitTests/1_eventstore/checkOperationResult.test.ts

  1. /* eslint-disable @typescript-eslint/no-angle-bracket-type-assertion */
  2. /* eslint-disable @typescript-eslint/no-explicit-any */
  3.  
  4. import {TCPConnection} from '../../../src/eventstore/TCPConnection'
  5. import * as assert from 'assert'
  6. import {EventstoreSettings, setConnectionSettings} from '../../../src/eventstore/EventstoreSettings'
  7. import * as model from '../../../src/protobuf/model'
  8.  
  9. describe('checkOperationResult', (): void => {
  10. const protobuf = model.eventstore.proto
  11.  
  12. class TestTCP extends TCPConnection {
  13. public constructor(connectionConfiguration: EventstoreSettings) {
  14. super(connectionConfiguration)
  15. }
  16.  
  17. public rejectCommandPromise(id: string, err): void {
  18. throw err
  19. }
  20.  
  21. public test(correlationId: string, result: number, message: string = ''): void {
  22. this.checkOperationResult(correlationId, result, message)
  23. }
  24. }
  25.  
  26. it('handles OperationResult.AccessDenied', (): void => {
  27. const testClass = new TestTCP(setConnectionSettings({}))
  28.  
  29. try {
  30. testClass.test('id', protobuf.OperationResult.AccessDenied)
  31. assert.fail('has not thrown')
  32. } catch (err) {
  33. assert.strictEqual(err.name, 'EventstoreAccessDeniedError')
  34. }
  35. })
  36.  
  37. it('handles OperationResult.CommitTimeout', (): void => {
  38. const testClass = new TestTCP(setConnectionSettings({}))
  39.  
  40. try {
  41. testClass.test('id', protobuf.OperationResult.CommitTimeout)
  42. assert.fail('has not thrown')
  43. } catch (err) {
  44. assert.strictEqual(err.name, 'EventstoreCommitTimeoutError')
  45. }
  46. })
  47.  
  48. it('handles OperationResult.ForwardTimeout', (): void => {
  49. const testClass = new TestTCP(setConnectionSettings({}))
  50.  
  51. try {
  52. testClass.test('id', protobuf.OperationResult.ForwardTimeout)
  53. assert.fail('has not thrown')
  54. } catch (err) {
  55. assert.strictEqual(err.name, 'EventstoreForwardTimeoutError')
  56. }
  57. })
  58.  
  59. it('handles OperationResult.InvalidTransaction', (): void => {
  60. const testClass = new TestTCP(setConnectionSettings({}))
  61.  
  62. try {
  63. testClass.test('id', protobuf.OperationResult.InvalidTransaction)
  64. assert.fail('has not thrown')
  65. } catch (err) {
  66. assert.strictEqual(err.name, 'EventstoreInvalidTransactionError')
  67. }
  68. })
  69.  
  70. it('handles OperationResult.PrepareTimeout', (): void => {
  71. const testClass = new TestTCP(setConnectionSettings({}))
  72.  
  73. try {
  74. testClass.test('id', protobuf.OperationResult.PrepareTimeout)
  75. assert.fail('has not thrown')
  76. } catch (err) {
  77. assert.strictEqual(err.name, 'EventstorePrepareTimeoutError')
  78. }
  79. })
  80.  
  81. it('handles OperationResult.StreamDeleted', (): void => {
  82. const testClass = new TestTCP(setConnectionSettings({}))
  83.  
  84. try {
  85. testClass.test('id', protobuf.OperationResult.StreamDeleted)
  86. assert.fail('has not thrown')
  87. } catch (err) {
  88. assert.strictEqual(err.name, 'EventstoreStreamDeletedError')
  89. }
  90. })
  91.  
  92. it('handles OperationResult.WrongExpectedVersion', (): void => {
  93. const testClass = new TestTCP(setConnectionSettings({}))
  94.  
  95. try {
  96. testClass.test('id', protobuf.OperationResult.WrongExpectedVersion)
  97. assert.fail('has not thrown')
  98. } catch (err) {
  99. assert.strictEqual(err.name, 'EventstoreWrongExpectedVersionError')
  100. }
  101. })
  102.  
  103. it('handles OperationResult.Unspecific', (): void => {
  104. const testClass = new TestTCP(setConnectionSettings({}))
  105.  
  106. try {
  107. testClass.test('id', 10)
  108. assert.fail('has not thrown')
  109. } catch (err) {
  110. assert.strictEqual(err.name, 'EventstoreUnspecificError')
  111. }
  112. })
  113. })