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

AN-297-Adding unit tests for Device Registry. #1343

Open
wants to merge 28 commits into
base: staging
Choose a base branch
from

Conversation

BenjaminSsempala
Copy link
Contributor

@BenjaminSsempala BenjaminSsempala commented Feb 15, 2023

WHAT DOES THIS PR DO?

  • Adding Unit Tests for device registry.

STATUS OF CODE COMPLETION

  • Utils

    • common
    • create-activity
    • create-airqloud
    • create-device
    • create-event
    • create-health-tips
    • create-location
    • create-monitor
    • create-photo
    • create-sensor
    • create-site
    • date
    • distance
    • errors
    • generate Filter
    • log
    • multitenancy

STATUS OF REVIEW

  • Utils
    • common
    • create-activity
    • create-airqloud
    • create-device
    • create-event
    • create-health-tips
    • create-location
    • create-monitor
    • create-photo
    • create-sensor
    • create-site
    • date
    • distance
    • errors
    • generate Filter
    • log
    • multitenancy

WHAT ISSUES ARE RELATED TO THIS PR?

HOW DO I TEST OUT THIS PR?

  • Check out this branch.
  • Run npm install
  • run mocha ./utils/test/ut_create-site.js --exit
    -You can currently test out the util tests depending on their indicated status of completion above. Simply replace the ut_create-site.js in the command below with the targeted test-file for the specific test, for-example ut_create-device.js

WHICH ENDPOINTS SHOULD BE READY FOR TESTING?:

IS THERE ANY JENKINS CONSOLE LINK FOR CODE COVERAGE AND BUILD INFO?

ARE THERE ANY RELATED PRs?

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

Device registry changes in this PR available for preview here

Copy link
Contributor

@Baalmart Baalmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BenjaminSsempala , I have just left some comments for your review. Thanks!

src/device-registry/config/constants.js Outdated Show resolved Hide resolved
@@ -1,3 +1,4 @@
require("module-alias/register");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the motivation for adding the "alias" module to this Models file? Does it help out in the testing process? @BenjaminSsempala

Copy link
Contributor Author

@BenjaminSsempala BenjaminSsempala Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Baalmart yes, I discovered it was required but I guess because I shifted focus to first finish utils, I'll look more into this as I go into models

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

Copy link
Contributor

@123MwanjeMike 123MwanjeMike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @BenjaminSsempala
This is really great work 👏👏👏
I have however just left a few comments that I think could be helpful in refactoring.
Thanks again

src/device-registry/models/test/ut_device.js Show resolved Hide resolved
let isValid = siteUtil.validateSiteName("134141341");
assert.equal(isValid, true, "the site name is longer than 4 characters");
it("should return true if the site name is not longer than 50 characters and shorter than 4 characters", function () {
let isValid = siteUtil.checkStringLength(stubValue.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of stubValue.name?
The test definition states that its length is

4 < stubValue.name < 51

However, I can't tell which edge case is being tested here.
Could we test both cases individually in this case for example
Have stubValue.name with a length less than 4, a value in the acceptable range, and a value greater than 50?

Comment on lines +331 to +335
// it("should generate a unique site name given the parish name", function () {

// const stub = sinon
// .stub(siteModel(stubValue.tenant), "create")
// .returns(stubValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a strong proponent of removing unused code rather than just commenting it out. This is because this code will always be available in the git history should you ever need it in the future.
However, this is not a big issue for now so no worries

{
params: {
locations: [{ lat: stubValue.latitude, lng: stubValue.longitude }],
key: process.env.GOOGLE_MAPS_API_KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to mock the Google maps api response and avoid passing in the actual key.
With this implementation, I can tell we are sending the test requests to google maps which may not be necessary cost wise

@Baalmart Baalmart reopened this May 11, 2023
@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@Baalmart Baalmart deleted the branch staging June 10, 2023 20:16
@Baalmart Baalmart closed this Jun 10, 2023
@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

let match;
while ((match = regex.exec(fileContent))) {
const testName = match[1];
const testCommand = `mocha ${filePath} --grep "${testName.replace(/"/g, '\\"')}" --exit`;

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This does not escape backslash characters in the input.
@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2023

Device registry changes in this PR available for preview here

@github-actions
Copy link
Contributor

Device registry changes in this PR available for preview here

@Baalmart
Copy link
Contributor

Hi @BenjaminSsempala , is this PR still relevant?
If not, please delete it accordingly and delete the branch afterwards.

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

Successfully merging this pull request may close these issues.

3 participants