Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/53/needs duplicate prevention #200

Draft
wants to merge 3 commits into
base: saga
Choose a base branch
from

Conversation

madcalf
Copy link
Contributor

@madcalf madcalf commented Nov 20, 2024

What changed?

Confirms that the required related fields (survey, region and item) are included
Checks for any existing entries with the same values for survey, region, subregion and item
Throws an error if duplicate entry is found and does not create the entry.

Closes #53

How can you test this?

Currently there are no automated tests. Best way to test is by sending post requests via an http client (e.g. Bruno, Postman, Insomnia).

  1. If your local db is empty, using the Content Manager, add several entries in the Survey, Region, Subregion and Item collections. Use the Id's from these items in the "connect" parts of the body data listed below.

  2. Use the following api for the remaining steps
    Request type: POST
    Request url: http://localhost:1337/api/needs?populate=*

  3. Create a post body that successfully creates an entry.

{
  "data": {
    "amount": 1,
    "survey": {
      "disconnect": [],
      "connect":[1]
    },
    "region": {
      "connect": [1]
    },
    "item": {
        "connect": [1]
    }
  }
}
  1. Send that same post again and confirm that it returns an error and does not create a duplicate entry

  2. Send a post request that is missing one or more required fields. Confirm that this returns an error and does not create an entry. For example, this one does not have a survey field:

    {
      "data": {
        "amount": 1,
        "region": {
          "connect": [1]
        },
        "item": {
            "connect": [1]
        }
      }
    }
  3. Send a post that has invalid ids for related data. Confirm that this returns an error and does not create an entry

    {
      "data": {
        "amount": 1,
        "survey": {
          "disconnect": [],
          "connect":[999]
        },
        "region": {
          "connect": [999]
        },
        "item": {
            "connect": [999]
        }
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat(data-modelling): Add custom error checking to the NeedsAssessment.Need collection
1 participant