Esempio n. 1
0
func TestNotify(t *testing.T) {
	render := new(tests.MockRender)
	db := new(tests.MockExecutor)
	repositories := new(tests.MockRepositories)

	notificator := new(tests.MockNotificator)
	peopleRepo := new(tests.MockPersonRepository)
	doorRepo := new(tests.MockDoorRepository)

	account := &doorbot.Account{
		ID: 44,
	}

	person := &doorbot.Person{
		AccountID:   44,
		ID:          45,
		Name:        "John Rambo",
		Email:       "*****@*****.**",
		IsVisible:   true,
		IsAvailable: true,
	}

	door := &doorbot.Door{}

	notification := Notification{
		DoorID:   33,
		PersonID: 45,
	}

	repositories.On("PersonRepository").Return(peopleRepo)
	repositories.On("DoorRepository").Return(doorRepo)
	repositories.On("DB").Return(db)

	peopleRepo.On("Find", db, uint(45)).Return(person, nil)
	doorRepo.On("Find", db, uint(33)).Return(door, nil)

	notificator.On("Notify", account, door, person).Return(nil)

	vm := ViewModel{Notification: &notification}

	render.On("JSON", http.StatusAccepted, ViewModel{Notification: &notification}).Return()

	Notify(render, account, repositories, notificator, vm)

	render.Mock.AssertExpectations(t)
	peopleRepo.Mock.AssertExpectations(t)
	doorRepo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
	notificator.Mock.AssertExpectations(t)
}
Esempio n. 2
0
func TestRegister(t *testing.T) {
	render := new(tests.MockRender)
	notificator := new(tests.MockNotificator)

	accountRepo := new(tests.MockAccountRepository)
	authRepo := new(tests.MockAuthenticationRepository)
	personRepo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)
	tx := new(tests.MockTransaction)

	config := &doorbot.DoorbotConfig{}

	repositories := new(tests.MockRepositories)
	repositories.On("AccountRepository").Return(accountRepo)
	repositories.On("PersonRepository").Return(personRepo)
	repositories.On("AuthenticationRepository").Return(authRepo)
	repositories.On("SetAccountScope", uint(0)).Return()

	repositories.On("DB").Return(db)
	repositories.On("Transaction").Return(tx, nil)

	vm := RegisterViewModel{
		Account: AccountRegisterRequest{
			Name: "ACME",
		},
	}

	var noAccount *doorbot.Account

	accountRepo.On("FindByHost", db, mock.AnythingOfType("string")).Return(noAccount, nil)
	accountRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Account")).Return(nil)
	personRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Person")).Return(nil)
	authRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Authentication")).Return(nil)

	notificator.On("AccountCreated", mock.AnythingOfType("*doorbot.Account"), mock.AnythingOfType("*doorbot.Person"), mock.AnythingOfType("string")).Return()
	tx.On("Commit").Return(nil)

	render.On("JSON", http.StatusCreated, mock.AnythingOfType("AccountViewModel")).Return()

	Register(render, config, repositories, notificator, vm)

	render.Mock.AssertExpectations(t)
	accountRepo.Mock.AssertExpectations(t)
	personRepo.Mock.AssertExpectations(t)
	authRepo.Mock.AssertExpectations(t)
}