# Checking the unit tests of ScholarX backend

**URL:** <https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297>\
**Category:** ScholarX\
**Created:** [June 16, 2021, 5:18pm UTC](https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297 "2021-06-16T17:18:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![piumal1999](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/piumal1999/32/274_2.png) [@piumal1999](https://sef.discourse.group/u/piumal1999)\
**Post date:** [June 16, 2021, 5:18pm UTC](https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297/1 "2021-06-16T17:18:06Z")

</div>

In the ScholarX backend, some unit tests are missing so we need to add those tests. Previously we had created unit tests for most of the endpoints and service methods. Since few months I noticed that the tests don’t run when building the backend. So I checked the backend and found that the unit tests are in the wrong directory.

But after moving it to the right directory, it throws errors because some controllers and methods have changed.

The swagger UI is also not working now, so we have to fix that too.

To add the missing unit tests, we have to do these things:

1. Fix the directory
2. Fix the existing tests
3. Fix the swagger UI
4. Find out the missing unit tests
5. Add the missing tests

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [June 16, 2021, 6:56pm UTC](https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297/2 "2021-06-16T18:56:09Z")

</div>

Thanks @piumal1999 for having a look at this task.  
Shall we break down these steps into issues.  
My suggestion is,

1. Issue for dir fix.
2. Individual issues for each endpoint to fix the existing unit tests.
3. Individual issues for each endpoint to add missing tests.
4. Issue for Swagger UI fix.  
test issues should mention to add tests(if missing) for the controller and its service methods.

---

<div class="post-metadata">

**Author:** ![piumal1999](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/piumal1999/32/274_2.png) [@piumal1999](https://sef.discourse.group/u/piumal1999)\
**Post date:** [June 18, 2021, 5:59pm UTC](https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297/3 "2021-06-18T17:59:18Z")

</div>

Yeah. That’s a good suggestion.

> [@YohanAvishke](#):
>
> Individual issues for each endpoint to fix the existing unit tests.

So we can also assign the new contributors for those

Btw, I tried fixing the directory issue. But before merging, we have to fix the existing tests from that PR. previously we had nearly 100 unit tests, and most of them are failing due to endpoint changes. I was able to fix 50 of them. For the rest, I need to find a way to create a mock authentication principal.

Draft PR:

> <https://github.com/sef-global/scholarx-backend-v1/pull/169>
>
> \## Purpose
> 
> The purpose of this PR is to fix #168 
> 
> \## Goals
> 
> Fixing the t…est directory
> Fixing the existing unit tests
> 
> \## Approach
> 
> 
> \## Checklist
> \- \[x\] This PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
> \- \[x\] I have read and understood the development best practices guidelines ( http://bit.ly/sef-best-practices )
> \- \[x\] My code follows the style guidelines of this project
> \- \[x\] I have performed a self-review of my own code
> \- \[x\] I have commented my code, particularly in hard-to-understand areas
> \- \[\] I have made corresponding changes to the documentation
> 
> \## Related PRs
>  
> N/A
> 
> \## Test environment
>  
> Travis CI
> !\[image\](https://user-images.githubusercontent.com/27498587/142731934-2fd5f671-1b0a-4f32-b4f2-fb3740b628f6.png)
> 
> 
> \## Learning

---

<div class="post-metadata">

**Author:** ![piumal1999](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/piumal1999/32/274_2.png) [@piumal1999](https://sef.discourse.group/u/piumal1999)\
**Post date:** [July 3, 2021, 7:45am UTC](https://sef.discourse.group/t/checking-the-unit-tests-of-scholarx-backend/297/4 "2021-07-03T07:45:35Z")

</div>

I was able to fix the authentication issue in unit tests. What I did was creating an authentication principal manually in the tests.

Updated the Pull request.

> <https://github.com/sef-global/scholarx/pull/169>
>
> \## Purpose
> 
> The purpose of this PR is to fix #168 
> 
> \## Goals
> 
> Fixing the t…est directory
> Fixing the existing unit tests
> 
> \## Approach
> 
> 
> \## Checklist
> \- \[x\] This PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
> \- \[x\] I have read and understood the development best practices guidelines ( http://bit.ly/sef-best-practices )
> \- \[x\] My code follows the style guidelines of this project
> \- \[x\] I have performed a self-review of my own code
> \- \[x\] I have commented my code, particularly in hard-to-understand areas
> \- \[\] I have made corresponding changes to the documentation
> 
> \## Related PRs
>  
> N/A
> 
> \## Test environment
>  
> 
> \## Learning

Next we’ll have to find the missing tests and add those. I’ll create a document with available and missing unit test details
