func GetImplementedTestCases(disco *discovery.ModelDiscoveryItem, nameGenerator names.Generator, ctx *model.Context, headlessTokenAcquisition bool, genConfig GeneratorConfig) ([]model.TestCase, map[string]string) {
	logger := logrus.StandardLogger()
	originalEndpoints := make(map[string]string)
	var testcases []model.TestCase
	endpoints := disco.Endpoints
	doc, err := loadSpec(disco.APISpecification.SchemaVersion, false)
	if err != nil {
		logger.Errorln(err)
		return nil, nil
	}

	for _, v := range endpoints {
		var responseCodes []int
		var goodResponseCode int
		newpath := getResourceIds(disco, v.Path, genConfig)

		for path, props := range doc.Spec().Paths.Paths {
			for meth, op := range getOperations(&props) {
				if (meth == v.Method) && (v.Path == path) {
					responseCodes = getResponseCodes(op)
					goodResponseCode, err = getGoodResponseCode(responseCodes)
					if err != nil {
						logger.WithFields(logrus.Fields{
							"testcase": op.Summary,
							"method":   meth,
							"endpoint": newpath,
							"err":      err,
						}).Error("Cannot get good response code")
						return nil, nil
					}

					headers := map[string]string{
						"Authorization":         "Bearer $access_token",
						"X-Fapi-Financial-Id":   "$fapi_financial_id",
						"X-Fapi-Interaction-Id": "b4405450-febe-11e8-80a5-0fcebb1574e1",
						"Content-Type":          "application/json",
						"User-Agent":            httpUserAgent,
						"Accept":                "*/*",
					}

					if strings.Contains(newpath, "account-access-consents") { // consent endpoints require a different access_token + custom chain
						headers["Authorization"] = "Bearer $client_access_token"
						customTestCases, err := getTemplatedTestCases(newpath)
						if err != nil {
							logger.WithFields(logrus.Fields{
								"testcase": op.Summary,
								"method":   meth,
								"endpoint": newpath,
								"err":      err,
							}).Warn("error getting Templated TestCase")
							return nil, nil
						}
						for i := range customTestCases {
							showReplacementErrors := false
							customTestCases[i].ProcessReplacementFields(ctx, showReplacementErrors)
						}
						if customTestCases != nil {
							testcases = append(testcases, customTestCases...)
						}
						continue
					}

					input := model.Input{Method: meth, Endpoint: newpath, Headers: headers}
					expect := model.Expect{StatusCode: goodResponseCode, SchemaValidation: true}
					context := model.Context{"baseurl": disco.ResourceBaseURI}
					testcase := model.TestCase{ID: nameGenerator.Generate(), Input: input, Context: context, Expect: expect, Name: op.Summary}
					if !headlessTokenAcquisition {
						showReplacementErrors := false
						testcase.ProcessReplacementFields(ctx, showReplacementErrors)
					}
					originalEndpoints[testcase.ID] = v.Path // capture original spec paths
					testcases = append(testcases, testcase)
					break
				}
			}
		}
	}
	return testcases, originalEndpoints
}
// GetImplementedTestCases takes a discovery Model and determines the implemented endpoints.
// Currently this function is experimental - meaning it contains fmt.Printlns as an aid to understanding
// and conceptualisation
GetImplementedTestCases takes a discovery Model and determines the implemented endpoints.
Currently this function is experimental - meaning it contains fmt.Printlns as an aid to understanding
and conceptualisation
// GetImplementedTestCases takes a discovery Model and determines the implemented endpoints . // Currently this function is experimental - meaning it contains fmt . Printlns as an aid to understanding // and conceptualisation
func GetImplementedTestCases(disco *discovery.ModelDiscoveryItem, nameGenerator names.Generator, ctx *model.Context, headlessTokenAcquisition bool, genConfig GeneratorConfig) ([]model.TestCase, map[string]string) {
	logger := logrus.StandardLogger()
	originalEndpoints := make(map[string]string)
	var testcases []model.TestCase
	endpoints := disco.Endpoints
	doc, err := loadSpec(disco.APISpecification.SchemaVersion, false)
	if err != nil {
		logger.Errorln(err)
		return nil, nil
	}
	for _, v := range endpoints {
		var responseCodes []int
		var goodResponseCode int
		newpath := getResourceIds(disco, v.Path, genConfig)
		for path, props := range doc.Spec().Paths.Paths {
			for meth, op := range getOperations(&props) {
				if (meth == v.Method) && (v.Path == path) {
					responseCodes = getResponseCodes(op)
					goodResponseCode, err = getGoodResponseCode(responseCodes)
					if err != nil {
						logger.WithFields(logrus.Fields{
							"testcase": op.Summary,
							"method":   meth,
							"endpoint": newpath,
							"err":      err,
						}).Error("Cannot get good response code")
						return nil, nil
					}
					headers := map[string]string{
						"Authorization":         "Bearer $access_token",
						"X-Fapi-Financial-Id":   "$fapi_financial_id",
						"X-Fapi-Interaction-Id": "b4405450-febe-11e8-80a5-0fcebb1574e1",
						"Content-Type":          "application/json",
						"User-Agent":            httpUserAgent,
						"Accept":                "*/*",
					}
					if strings.Contains(newpath, "account-access-consents") { 
						headers["Authorization"] = "Bearer $client_access_token"
						customTestCases, err := getTemplatedTestCases(newpath)
						if err != nil {
							logger.WithFields(logrus.Fields{
								"testcase": op.Summary,
								"method":   meth,
								"endpoint": newpath,
								"err":      err,
							}).Warn("error getting Templated TestCase")
							return nil, nil
						}
						for i := range customTestCases {
							showReplacementErrors := false
							customTestCases[i].ProcessReplacementFields(ctx, showReplacementErrors)
						}
						if customTestCases != nil {
							testcases = append(testcases, customTestCases...)
						}
						continue
					}
					input := model.Input{Method: meth, Endpoint: newpath, Headers: headers}
					expect := model.Expect{StatusCode: goodResponseCode, SchemaValidation: true}
					context := model.Context{"baseurl": disco.ResourceBaseURI}
					testcase := model.TestCase{ID: nameGenerator.Generate(), Input: input, Context: context, Expect: expect, Name: op.Summary}
					if !headlessTokenAcquisition {
						showReplacementErrors := false
						testcase.ProcessReplacementFields(ctx, showReplacementErrors)
					}
					originalEndpoints[testcase.ID] = v.Path 
					testcases = append(testcases, testcase)
					break
				}
			}
		}
	}
	return testcases, originalEndpoints
}
func GetImplementedTestCases ( disco * discovery . ModelDiscoveryItem , nameGenerator names . Generator , ctx * model . Context , headlessTokenAcquisition bool , genConfig GeneratorConfig ) ( [ ] model . TestCase , map [ string ] string ) { logger := logrus . StandardLogger ( ) originalEndpoints := make ( map [ string ] string ) var testcases [ ] model . TestCase endpoints := disco . Endpoints doc , err := loadSpec ( disco . APISpecification . SchemaVersion , false ) if err != nil { logger . Errorln ( err ) return nil , nil } for _ , v := range endpoints { var responseCodes [ ] int var goodResponseCode int newpath := getResourceIds ( disco , v . Path , genConfig ) for path , props := range doc . Spec ( ) . Paths . Paths { for meth , op := range getOperations ( & props ) { if ( meth == v . Method ) && ( v . Path == path ) { responseCodes = getResponseCodes ( op ) goodResponseCode , err = getGoodResponseCode ( responseCodes ) if err != nil { logger . WithFields ( logrus . Fields { " " : op . Summary , " " : meth , " " : newpath , " " : err , } ) . Error ( " " ) return nil , nil } headers := map [ string ] string { " " : " " , " " : " " , " " : " " , " " : " " , " " : httpUserAgent , " " : " " , } if strings . Contains ( newpath , " " ) { headers [ " " ] = " " customTestCases , err := getTemplatedTestCases ( newpath ) if err != nil { logger . WithFields ( logrus . Fields { " " : op . Summary , " " : meth , " " : newpath , " " : err , } ) . Warn ( " " ) return nil , nil } for i := range customTestCases { showReplacementErrors := false customTestCases [ i ] . ProcessReplacementFields ( ctx , showReplacementErrors ) } if customTestCases != nil { testcases = append ( testcases , customTestCases ... ) } continue } input := model . Input { Method : meth , Endpoint : newpath , Headers : headers } expect := model . Expect { StatusCode : goodResponseCode , SchemaValidation : true } context := model . Context { " " : disco . ResourceBaseURI } testcase := model . TestCase { ID : nameGenerator . Generate ( ) , Input : input , Context : context , Expect : expect , Name : op . Summary } if ! headlessTokenAcquisition { showReplacementErrors := false testcase . ProcessReplacementFields ( ctx , showReplacementErrors ) } originalEndpoints [ testcase . ID ] = v . Path testcases = append ( testcases , testcase ) break } } } } return testcases , originalEndpoints }
GetImplementedTestCases takes a discovery Model and determines the implemented endpoints.
GetImplementedTestCases takes a discovery Model and determines the implemented endpoints .
// consent endpoints require a different access_token + custom chain // capture original spec paths