})

	Describe("Upsert", func() {
		Context("POST", func() {
			var (
				tcpMapping  db.TcpRouteMapping
				tcpMappings []db.TcpRouteMapping
			)

			BeforeEach(func() {
				tcpMapping = db.NewTcpRouteMapping("router-group-guid-001", 52000, "1.2.3.4", 60000)
				tcpMappings = []db.TcpRouteMapping{tcpMapping}
			})

			It("checks for routing.routes.write scope", func() {
				request = handlers.NewTestRequest(tcpMappings)

				tcpRouteMappingsHandler.Upsert(responseRecorder, request)
				Expect(responseRecorder.Code).To(Equal(http.StatusCreated))

				_, permission := token.DecodeTokenArgsForCall(0)
				Expect(permission).To(ConsistOf(handlers.RoutingRoutesWriteScope))
			})

			Context("when all inputs are present and correct", func() {
				It("returns an http status created", func() {
					request = handlers.NewTestRequest(tcpMappings)
					tcpRouteMappingsHandler.Upsert(responseRecorder, request)

					Expect(responseRecorder.Code).To(Equal(http.StatusCreated))
				})
		validator        *fake_validator.FakeRouteValidator
		token            *fake_token.FakeToken
	)

	BeforeEach(func() {
		database = &fake_db.FakeDB{}
		validator = &fake_validator.FakeRouteValidator{}
		token = &fake_token.FakeToken{}
		logger = lagertest.NewTestLogger("routing-api-test")
		routesHandler = handlers.NewRoutesHandler(token, 50, validator, database, logger)
		responseRecorder = httptest.NewRecorder()
	})

	Describe(".List", func() {
		It("response with a 200 OK", func() {
			request = handlers.NewTestRequest("")

			routesHandler.List(responseRecorder, request)

			Expect(responseRecorder.Code).To(Equal(http.StatusOK))
		})

		It("checks for route.admin scope", func() {
			request = handlers.NewTestRequest("")

			routesHandler.List(responseRecorder, request)
			_, permission := token.DecodeTokenArgsForCall(0)
			Expect(permission).To(ConsistOf(handlers.AdminRouteScope))
		})

		Context("when the UAA token is not valid", func() {
			)

			BeforeEach(func() {
				tcpMapping = models.TcpRouteMapping{
					TcpRoute: models.TcpRoute{
						RouterGroupGuid: "router-group-guid-001",
						ExternalPort:    52000,
					},
					HostIP:   "1.2.3.4",
					HostPort: 60000,
				}
				tcpMappings = []models.TcpRouteMapping{tcpMapping}
			})

			It("checks for routing.routes.write scope", func() {
				request = handlers.NewTestRequest(tcpMappings)

				tcpRouteMappingsHandler.Upsert(responseRecorder, request)
				Expect(responseRecorder.Code).To(Equal(http.StatusCreated))

				_, permission := fakeClient.DecodeTokenArgsForCall(0)
				Expect(permission).To(ConsistOf(handlers.RoutingRoutesWriteScope))
			})

			Context("when all inputs are present and correct", func() {
				It("returns an http status created", func() {
					request = handlers.NewTestRequest(tcpMappings)
					tcpRouteMappingsHandler.Upsert(responseRecorder, request)

					Expect(responseRecorder.Code).To(Equal(http.StatusCreated))
				})