I was thinkig a lot on WHAT to test in a method that works like an "orchestrator" and it's only job is to calls functions. So I have this BattleInteractor class
class BattleInteractor {
constructor(opts) {
this.battleRepository = opts.battleRepository
this.battleEntity = opts.battleEntity
this.battleWinner = opts.battleWinner
this.typeFactoryService = opts.typeFactory
}
async execute(pokemonOne, pokemonTwo) {
const battleResult = this.battle(pokemonOne, pokemonTwo)
return battleResult
}
battle(pokemonOne, pokemonTwo) {
const strategy = this.typeFactoryService.getStrategy(pokemonOne, pokemonTwo)
const pokemonsSetted = strategy.setStats(pokemonOne, pokemonTwo)
const battleResult = this.battleEntity.battleLogic(pokemonsSetted)
return this.battleWinner.battleWinner(battleResult)
}
}
module.exports = BattleInteractor
And the test file with all methods mocked:
const BattleInteractor = require('../../../../src/application/useCases/battle/battleInteractor')
describe('BattleInteractor test', () => {
const pokemonOneMock = 'mock'
const pokemonTwoMock = 'mock'
const battleWinnerMock = 'mock'
class TypeMock {
setStats() {
return 'mockStats'
}
}
const battleInteractor = new BattleInteractor({
battleRepository: {
savedDatabase: () => true
},
typeFactory: {
getStrategy: () => {
return new TypeMock()
},
},
battleEntity: {
battleLogic: () => {
return "battleLogicMock"
}
},
battleWinner: {
battleWinner: () => {
return battleWinnerMock
}
},
})
test.only('Should return properties formatted', async () => {
const res = await battleInteractor.execute(pokemonOneMock, pokemonTwoMock)
expect(res.message).toBe("carnivine and naganadel have tied")
})
})
All works fine, so I have some questions: What should I test in a method like this? Is this a unit testing or a integration testing? How necessary is it to test a class/method like this?