-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3705 from airqo-platform/staging
move to production
- Loading branch information
Showing
23 changed files
with
1,216 additions
and
1,323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require("module-alias/register"); | ||
const { expect } = require("chai"); | ||
const sinon = require("sinon"); | ||
const setDefaultTenant = require("@middleware/setDefaultTenant"); | ||
const constants = require("@config/constants"); | ||
|
||
describe("setDefaultTenant Middleware", () => { | ||
let req, res, next; | ||
|
||
beforeEach(() => { | ||
req = { | ||
query: {}, | ||
}; | ||
res = {}; | ||
next = sinon.stub(); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); // Restore the original functionality of stubbed methods | ||
}); | ||
|
||
it("should set the default tenant if tenant is empty", () => { | ||
// Set up the constant for testing | ||
constants.DEFAULT_TENANT = "defaultTenant"; | ||
|
||
const middleware = setDefaultTenant; | ||
middleware(req, res, next); | ||
|
||
expect(req.query.tenant).to.equal("defaultTenant"); | ||
expect(next.calledOnce).to.be.true; // Ensure next() is called | ||
}); | ||
|
||
it("should keep the existing tenant if provided", () => { | ||
req.query.tenant = "customTenant"; | ||
|
||
const middleware = setDefaultTenant; | ||
middleware(req, res, next); | ||
|
||
expect(req.query.tenant).to.equal("customTenant"); | ||
expect(next.calledOnce).to.be.true; // Ensure next() is called | ||
}); | ||
|
||
it("should use 'airqo' as the default tenant if no constant is defined", () => { | ||
// Temporarily remove DEFAULT_TENANT for this test | ||
const originalDefaultTenant = constants.DEFAULT_TENANT; | ||
delete constants.DEFAULT_TENANT; | ||
|
||
const middleware = setDefaultTenant; | ||
middleware(req, res, next); | ||
|
||
expect(req.query.tenant).to.equal("airqo"); | ||
expect(next.calledOnce).to.be.true; // Ensure next() is called | ||
|
||
// Restore the original constant value after test | ||
constants.DEFAULT_TENANT = originalDefaultTenant; | ||
}); | ||
}); |
Oops, something went wrong.