# 13.4 Agregar pruebas a tus servicios

Puedes agregar el cóodigo javascript para probar que lo que regresa el servicio es correcto.&#x20;

{% hint style="info" %}
Se sugiere probar los casos de uso correctos e incorrectos, y probar que se regresen correctamente los resultados.
{% endhint %}

Para probar que el servicio de login con un usuario correcto validaré lo siguiente:

* Que el servicio regrese un status 200
* Que el servicio regrese un token que no este vacío

Para probar tipos de datos voy a probar

* Que el token sea string
* Que la fecha de expiración del token sea un date con el formato&#x20;

En Postman:

1. Da clic en la pestaña de Tests
2. Agrega el código

   ```
   //Funciones de fecha
   const moment = require("moment")

   //Revisar Estatus 200
   pm.test("Estatus es 200", function () {
       pm.response.to.be.ok;
   });

   //Convertir el Json a un objeto
   var respuesta = pm.response.json();

   pm.test("Token no es vacío", function() 
   {
       pm.expect(respuesta.Token).not.to.be.empty;
   });

   pm.test("Token es string", function() 
   {
       pm.expect(respuesta.Token).to.be.a('string');
   });

   pm.test("Token Expiration es una fecha correcta", function () {
      pm.expect(moment(respuesta.TokenExpiration,"MM-MM-DD hh:mm:ss").isValid()).to.be.true
   });

   ```
3. Da clic en el botón Send
4. En la pestaña de Test Results puedes ver el resultado de los Tests

![](/files/-MOwMEWmrzx9-JJyp1Bk)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://abi.gitbook.io/net-core/14.-introduccion-a-postman/14.4-agregar-pruebas-a-tus-servicios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
