當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript authorization-check.checkAuthorizationGuards函數代碼示例

本文整理匯總了TypeScript中test/features/offer/routes/checks/authorization-check.checkAuthorizationGuards函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript checkAuthorizationGuards函數的具體用法?TypeScript checkAuthorizationGuards怎麽用?TypeScript checkAuthorizationGuards使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了checkAuthorizationGuards函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

  describe('on GET', () => {
    checkAuthorizationGuards(app, 'get', confirmationPage)

    context('when user authorised', () => {
      beforeEach(() => {
        idamServiceMock.resolveRetrieveUserFor('1', 'citizen')
      })

      it('should return 500 and render error page when cannot retrieve claims', async () => {
        claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

        await request(app)
          .get(confirmationPage)
          .set('Cookie', `${cookieName}=ABC`)
          .expect(res => expect(res).to.be.serverError.withText('Error'))
      })

      it('should render page when everything is fine', async () => {
        claimStoreServiceMock.resolveRetrieveClaimByExternalId()
        await request(app)
          .get(confirmationPage)
          .set('Cookie', `${cookieName}=ABC`)
          .expect(res => expect(res).to.be.successful.withText('We’ve sent your offer'))
      })
    })
  })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:26,代碼來源:offer-confirmation.ts

示例2: describe

  describe('on GET', () => {
    checkAuthorizationGuards(app, 'get', Paths.agreementReceiver.evaluateUri({ externalId: externalId }))

    describe('for authorized user', () => {
      beforeEach(() => {
        idamServiceMock.resolveRetrieveUserFor('1', 'citizen')
      })

      it('should return 500 and render error page when cannot retrieve claim by external id', async () => {
        claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

        await request(app)
          .get(Paths.agreementReceiver.evaluateUri({ externalId: externalId }))
          .set('Cookie', `${cookieName}=ABC`)
          .expect(res => expect(res).to.be.serverError.withText('Error'))
      })

      it('should return 500 and render error page when cannot generate PDF', async () => {
        claimStoreServiceMock.resolveRetrieveClaimByExternalId()
        claimStoreServiceMock.rejectRetrieveDocument('Something went wrong')

        await request(app)
          .get(Paths.agreementReceiver.evaluateUri({ externalId: externalId }))
          .set('Cookie', `${cookieName}=ABC`)
          .expect(res => expect(res).to.be.serverError.withText('Error'))
      })

      it('should return receipt when everything is fine', async () => {
        claimStoreServiceMock.resolveRetrieveClaimByExternalId()
        claimStoreServiceMock.resolveRetrieveDocument()

        await request(app)
          .get(Paths.agreementReceiver.evaluateUri({ externalId: externalId }))
          .set('Cookie', `${cookieName}=ABC`)
          .expect(res => expect(res).to.be.successful)
      })
    })
  })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:38,代碼來源:agreement.ts

示例3: describe

    describe('on POST', () => {
      checkAuthorizationGuards(app, 'post', responsePage)

      context('when user authorised', () => {
        beforeEach(() => {
          idamServiceMock.resolveRetrieveUserFor('1', 'citizen', 'defendant')
        })

        context('when middleware failure', () => {

          it('should return 500 when cannot retrieve claim by external id', async () => {
            claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

            await request(app)
              .post(responsePage)
              .set('Cookie', `${cookieName}=ABC`)
              .send({})
              .expect(res => expect(res).to.be.serverError.withText('Error'))
          })
        })

        context('when form is valid', async () => {

          it('should redirect to make a legal agreement page when offer is accepted', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            const formData = {
              option: StatementType.ACCEPTATION.value
            }
            await request(app)
              .post(responsePage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(formData)
              .expect(res => expect(res).to.be.redirect.toLocation(makeLegalAgreementPage))
          })

          it('should submit rejection and redirect to confirmation page', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            claimStoreServiceMock.resolveRejectOffer()
            const formData = {
              option: StatementType.REJECTION.value
            }
            await request(app)
              .post(responsePage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(formData)
              .expect(res => expect(res).to.be.redirect.toLocation(rejectedOfferPage))
          })
        })

        context('when form is invalid', async () => {

          it('should render page with errors', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            const formData = {
              option: undefined
            }
            await request(app)
              .post(responsePage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(formData)
              .expect(res => expect(res).to.be.successful.withText('Choose option: yes or no or make an offer', 'div class="error-summary"'))
          })
        })
      })
    })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:65,代碼來源:response.ts

示例4: describe

    describe('on POST', () => {
      checkAuthorizationGuards(app, 'post', declarationPage)

      context('when user authorised', () => {
        beforeEach(() => {
          idamServiceMock.resolveRetrieveUserFor('1', 'citizen', 'defendant')
        })

        context('when middleware failure', () => {
          it('should return 500 when cannot retrieve claim by external id', async () => {
            claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

            await request(app)
              .post(declarationPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send({})
              .expect(res => expect(res).to.be.serverError.withText('Error'))
          })
        })

        context('when form is valid', () => {
          context('when accepting offer as claimant', () => {
            it('should accepted offer and redirect to confirmation page', async () => {
              claimStoreServiceMock.resolveRetrieveClaimByExternalId()
              claimStoreServiceMock.resolveAcceptOffer()
              const formData = {
                signed: 'true'
              }
              await request(app)
                .post(declarationPage)
                .set('Cookie', `${cookieName}=ABC`)
                .send(formData)
                .expect(res => expect(res).to.be.redirect.toLocation(acceptedPage))
            })
          })

          context('when countersigning offer as defendant', () => {
            const override: object = {
              submitterId: '123',
              defendantId: '1',
              settlement: {
                partyStatements: [
                  {
                    type: StatementType.OFFER.value,
                    madeBy: MadeBy.DEFENDANT.value,
                    offer: { content: 'offer text', completionDate: '2017-08-08' }
                  },
                  {
                    type: StatementType.ACCEPTATION.value,
                    madeBy: MadeBy.CLAIMANT.value
                  }
                ]
              }
            }
            it('should countersign offer and redirect to confirmation page when offer accepted by claimant', async () => {
              claimStoreServiceMock.resolveRetrieveClaimByExternalId(override)
              claimStoreServiceMock.resolveCountersignOffer()
              await request(app)
                .post(declarationPage)
                .set('Cookie', `${cookieName}=ABC`)
                .send({ signed: 'true' })
                .expect(res => expect(res).to.be.redirect.toLocation(settledPage))
            })
          })
        })

        context('when form is invalid', async () => {
          it('should render page with errors', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            const formData = {
              signed: undefined
            }
            await request(app)
              .post(declarationPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(formData)
              .expect(res => expect(res).to.be.successful.withText('Please select I confirm I’ve read and accept the terms of the agreement.', 'div class="error-summary"'))
          })
        })
      })
    })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:81,代碼來源:declaration.ts

示例5: describe

    describe('on POST', () => {
      checkAuthorizationGuards(app, 'post', offerPage)

      context('when user authorised', () => {
        beforeEach(() => {
          idamServiceMock.resolveRetrieveUserFor('1', 'citizen')
        })

        context('when middleware failure', () => {
          it('should return 500 when cannot retrieve claim by external id', async () => {
            claimStoreServiceMock.rejectRetrieveClaimByExternalId('HTTP error')

            await request(app)
              .post(offerPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(validFormData)
              .expect(res => expect(res).to.be.serverError.withText('Error'))
          })
        })

        context('when form is valid', async () => {
          it('should redirect to offer confirmation page', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            claimStoreServiceMock.resolveSaveOffer()
            const futureDate = moment().add(1, 'day')
            const formData = {
              offerText: 'Offer Text',
              completionDate: new LocalDate(futureDate.year(), futureDate.month() + 1, futureDate.date())
            }
            await request(app)
              .post(offerPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(formData)
              .expect(res => expect(res).to.be.redirect.toLocation(confirmationPage))
          })

          it('should return 500 and render error page when cannot save offer', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            claimStoreServiceMock.rejectSaveOfferForDefendant()

            await request(app)
              .post(offerPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send(validFormData)
              .expect(res => expect(res).to.be.serverError.withText('Error'))
          })
        })

        context('when provided date is in past', async () => {
          it('should render page with error', async () => {
            claimStoreServiceMock.resolveRetrieveClaimByExternalId()
            await request(app)
              .post(offerPage)
              .set('Cookie', `${cookieName}=ABC`)
              .send({
                offerText: 'Offer Text',
                completionDate: new LocalDate(1980, 1, 1)
              })
              .expect(res => expect(res).to.be.successful.withText('Enter an offer date in the future', 'div class="error-summary"'))
          })
        })
      })
    })
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:63,代碼來源:your-offer.ts


注:本文中的test/features/offer/routes/checks/authorization-check.checkAuthorizationGuards函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。