예제 #1
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestGet(t *testing.T) {

	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)
	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)

	params := martini.Params{
		"id": "33",
	}

	door := &doorbot.Door{
		ID:   33,
		Name: "ACME",
	}

	render.On("JSON", http.StatusOK, DoorViewModel{Door: door}).Return(nil)
	repo.On("Find", db, uint(33)).Return(door, nil)

	Get(render, repositories, params)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #2
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestDelete(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "33",
	}

	door := &doorbot.Door{
		ID:   33,
		Name: "ACME",
	}

	repo.On("Find", db, uint(33)).Return(door, nil)
	repo.On("Delete", db, door).Return(true, nil)

	render.On("Status", http.StatusNoContent).Return()

	Delete(render, repositories, params)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #3
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestDeleteFailed(t *testing.T) {
	repo := new(tests.MockDoorRepository)
	render := new(tests.MockRender)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "55",
	}

	door := &doorbot.Door{
		ID:   55,
		Name: "ACME",
	}

	repo.On("Find", db, uint(55)).Return(door, nil)
	repo.On("Delete", db, door).Return(false, errors.New("error"))

	render.On("Status", http.StatusInternalServerError).Return()

	Delete(render, repositories, params)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #4
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestDeleteNotFound(t *testing.T) {
	var door *doorbot.Door

	repo := new(tests.MockDoorRepository)
	render := new(tests.MockRender)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)

	params := martini.Params{
		"id": "44",
	}

	repo.On("Find", db, uint(44)).Return(door, nil)

	render.On("JSON", http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists"})).Return()

	Delete(render, repositories, params)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #5
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestPutFailed(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "5555",
	}

	postDoor := &doorbot.Door{
		Name: "Romanian Landlords",
	}

	repoDoor := &doorbot.Door{
		ID:   5555,
		Name: "ACME",
	}

	repo.On("Find", db, uint(5555)).Return(repoDoor, nil)
	repo.On("Update", db, repoDoor).Return(false, errors.New("failed"))

	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Put(render, repositories, params, DoorViewModel{Door: postDoor})

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #6
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestPostCreateError(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	door := &doorbot.Door{
		Name: "ACME",
	}

	repo.On("Create", db, door).Return(errors.New("errooor"))

	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Post(render, repositories, DoorViewModel{Door: door})

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #7
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestPost(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("AccountScope").Return(uint(1))

	db := new(tests.MockExecutor)
	repositories.On("DB").Return(db)

	door := &doorbot.Door{
		Name: "ACME",
	}

	repo.On("Create", db, door).Return(nil)

	render.On("JSON", http.StatusCreated, DoorViewModel{Door: door}).Return()

	Post(render, repositories, DoorViewModel{Door: door})

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #8
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestIndex(t *testing.T) {
	doors := []*doorbot.Door{
		&doorbot.Door{
			ID:        1,
			AccountID: 1,
			Name:      "A",
		},
	}

	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)
	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)

	repo.On("All", db).Return(doors, nil)
	render.On("JSON", http.StatusOK, DoorsViewModel{Doors: doors}).Return()

	Index(render, repositories)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #9
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)
}
예제 #10
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestIndexError(t *testing.T) {

	doors := []*doorbot.Door{}
	err := errors.New("i like pasta")

	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)
	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	repo.On("All", db).Return(doors, err)
	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Index(render, repositories)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
예제 #11
0
파일: doors_test.go 프로젝트: masom/doorbot
func TestPut(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("DoorRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "5555",
	}

	postDoor := &doorbot.Door{
		Name: "Romanian Landlords",
	}

	repoDoor := &doorbot.Door{
		ID:   5555,
		Name: "ACME",
	}

	repo.On("Find", db, uint(5555)).Return(repoDoor, nil)
	repo.On("Update", db, repoDoor).Return(true, nil)

	render.On("JSON", http.StatusOK, DoorViewModel{Door: repoDoor}).Return()

	Put(render, repositories, params, DoorViewModel{Door: postDoor})

	assert.Equal(t, "Romanian Landlords", repoDoor.Name)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}