Namespaces:
  test: io.murano.test

Name: TestMocks

Extends: test:TestFixture

Properties:
  logMessage:
    Contract: $.string()
    Default: 'Mock from property'

Methods:
  initialize:
    Body:
      - $.originalClass: new(TestMocksFixture)

  mock1:
    Body:
      - Return: 'This is mock1'

  testInjectMethodWithString:
    Body:
      - inject(TestMocksFixture, simpleMethod1, $this, mock1)

      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('This is mock1', $output)

  testInjectObjectWithString:
    Body:
      - inject($.originalClass, simpleMethod1, $this, mock1)

      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('This is mock1', $output)

  testInjectMethodWithYaqlExpr:
    Body:
      # Calling original method without mocking
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('method1', $output)

      - $mockText: 'I am mock'
      - inject(TestMocksFixture, simpleMethod1, $mockText)

      # Calling original method after mocking
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('I am mock', $output)

  testInjectMethodWithYaqlExpr2:
    Body:
      # Calling original method without mocking
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('method1', $output)

      - inject(TestMocksFixture, simpleMethod1, $.logMessage)

      # Calling mocked method
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('Mock from property', $output)

  testInjectObjectWithYaqlExpr:
    Body:
      # Calling original method without mocking
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('method1', $output)

      - $mockText: 'I am mock'
      - inject($.originalClass, simpleMethod1, $mockText)

      # Calling original method after mocking
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('I am mock', $output)

  testWithoriginal:
    Body:
      - inject(TestMocksFixture, simpleMethod1, withOriginal(t => $.originalClass.someProperty) -> $t)
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual(DEFAULT, $output)

  testOriginalMethod:
    Body:
      - inject(TestMocksFixture, simpleMethod1, originalMethod())
      - $output: $.originalClass.simpleMethod1()
      - $.assertEqual('method1', $output)