2

The following is the Body of the response:

{
    "downloadTime": "2021:03:17T17:52:21Z",
    "downloadTimeStamp": 1616003541,
    "genome": "hg38",
    "chrom": "chrX",
    "start": 51657026,
    "end": 51658026,
    "dna": "tatgacgtaactatccatttatttagatcatcctcaaaaatatctcagtacaattttcagtgtatagattttgccaccttttgtgagatttatccctaagtatttcatgtttttaatgttatcatgctggtatttttatttaaatatcaaattgtttgttagtaatatatagaacggcaagtgatttttatagatatagcaagggggttttttgcagattctataggattattttatagagatgatcacatcttcatagacaaaagagacagttttacttaccgctttccaagtttttcttctgacccttttattaacattttttcttgtattattgcactagttagattaagcggtggacaacatatttgcccacttttttttcattttaagaggtaagtactcagtcttcatcactacatttcaagttacctgtaggtttttcatagatgccatttccttatcaagttgaggaagattgcttctgtttctagtttggtaagagttttaccaggaatgaatgctggatttgccaaatgatgtttctgcgtctattaaaatgactattttacaaatctgttaatattgtgaattacattgatttgtttttctaaggttaaactacctttgcattctttggtcatgatgcattatccttttccccaggtaatactggcttcgtacaatgagtcaggaaatattccatttctttaattttctggaaaaaaaattctgtgggtggcattatttcttccttatatgattagtagaatccacaagtaaatccatctgggcctttaattttctttgtggaaggttttaaagtagaagcttaatgtattgaagagtgttttaatcacctcctatttatcccattagtgagggagggattcctgcctaggtttaggcaaatggctggcgtatgacacgacaccggacacatgagactgttagcaatttattagtaatgtatactcacaacctgagagaggaggatacc"
}

I have 2 questions:

1- I need to check if the “dna” contains at least 10 “Ngg” sites. That means if there are a minimum of 10 [acgt]gg sites (agg or cgg or tgg or ggg). How do I write a test for that?

2- Is the following test for validating schema correct?

const schema = {
  "downloadTime": "data-time",
  "genome": "{{human genome}}",  //human genome is a collection level variable
  "chrom": ("chrX"|"chrY"),
};
pm.test('Schema is valid', function() {
  pm.response.to.have.jsonSchema(schema);
});
2

I need to check if the “dna” contains at least 10 “Ngg” sites. That means if there are a minimum of 10 [acgt]gg sites (agg or cgg or tgg or ggg). How do I write a test for that?

You need to first find all such occurences:

resultArray = [...dna.matchAll(/[acgt]gg/g)]

then you need to assert the length:

pm.test('Number of occurences if equal or greater than 10', function() {
    pm.expect(resultArray.length).to.be.above(9);
});

All put together, it could look like so:

const jsonData = pm.response.json();

pm.test('Number of occurences is equal or greater than 10', function() {
    const dna = jsonData.dna;
    resultArray = [...dna.matchAll(/[acgt]gg/g)];
    pm.expect(resultArray.length).to.be.above(9);
});

Is the following test for validating schema correct?

Most certainly not. If I copy & paste it and use it as a test for a completely different response, the test passes. You, for example, don't specify any required properties as shown for example here.

1
  • Thank you SO much for taking the time to help! – Beeta Mar 19 at 13:53
2

I need to check if the “dna” contains at least 10 “Ngg” sites. That means if there are a minimum of 10 [acgt]gg sites (agg or cgg or tgg or ggg). How do I write a test for that?

pm.test('length validation', function () {
    pm.expect((pm.response.json().dna.match(/[acgt]gg/g) || []).length).to.be.greaterThan(10)
});

Is the following test for validating schema correct?

No:

Correct usage:

The supported json types are: https://json-schema.org/understanding-json-schema/reference/index.html

Numeric types
object
array
boolean
null

JSON schema is used to validate whether the required properties are present and is of the mentioned data type.

eg

const schema = {
  
    "type": "object",
    "properties": {
        
        "code": { "type": "string" }
    },
    "required":["code"]

}

pm.test('Schema is valid', function () {
    console.log(pm.response.json())
    pm.response.to.have.jsonSchema(schema);
});

Here it checks the response is an object meaning its inside {} , and has a required property called "code" and is string.

In your case you have to do value validation also

pm.response.json.downloadTime === //somevalidation for date-time
2
  • Thanks SO much for your thorough answer and for taking the time to help! – Beeta Mar 19 at 13:55
  • Please accept the answer that helped by clicking the tick sign – PDHide Mar 19 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.