diff --git a/Cargo.lock b/Cargo.lock index 228414c019..77f9b33ddc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7021,6 +7021,7 @@ dependencies = [ name = "test_utils" version = "0.1.0" dependencies = [ + "anyhow", "async-trait", "base64 0.22.0", "clap", diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 3b0dfe2b91..6d8663c030 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml @@ -14,6 +14,7 @@ payouts = [] [dependencies] async-trait = "0.1.79" +anyhow = "1.0.81" base64 = "0.22.0" clap = { version = "4.4.18", default-features = false, features = ["std", "derive", "help", "usage"] } rand = "0.8.5" diff --git a/crates/test_utils/src/connector_auth.rs b/crates/test_utils/src/connector_auth.rs index 3ba321c174..4b41506fe2 100644 --- a/crates/test_utils/src/connector_auth.rs +++ b/crates/test_utils/src/connector_auth.rs @@ -76,6 +76,7 @@ pub struct ConnectorAuthentication { pub zen: Option, pub zsl: Option, pub automation_configs: Option, + pub users: Option, } impl Default for ConnectorAuthentication { @@ -339,3 +340,12 @@ pub enum ConnectorAuthType { #[default] NoKey, } + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct UsersConfigs { + pub user_email: String, + pub user_password: String, + pub wrong_password: String, + pub user_base_email_for_signup: String, + pub user_domain_for_signup: String, +} diff --git a/crates/test_utils/src/main.rs b/crates/test_utils/src/main.rs index ba0d2eb358..5b56b9a0d1 100644 --- a/crates/test_utils/src/main.rs +++ b/crates/test_utils/src/main.rs @@ -1,9 +1,10 @@ use std::process::{exit, Command}; +use anyhow::Result; use test_utils::newman_runner; -fn main() { - let mut runner = newman_runner::generate_newman_command(); +fn main() -> Result<()> { + let mut runner = newman_runner::generate_runner()?; // Execute the newman command let output = runner.newman_command.spawn(); diff --git a/crates/test_utils/src/newman_runner.rs b/crates/test_utils/src/newman_runner.rs index c90292683f..29c15789cc 100644 --- a/crates/test_utils/src/newman_runner.rs +++ b/crates/test_utils/src/newman_runner.rs @@ -6,14 +6,23 @@ use std::{ process::{exit, Command}, }; -use clap::{arg, command, Parser}; +use anyhow::{Context, Result}; +use clap::{arg, command, Parser, ValueEnum}; use masking::PeekInterface; use regex::Regex; -use crate::connector_auth::{ConnectorAuthType, ConnectorAuthenticationMap}; +use crate::connector_auth::{ + ConnectorAuthType, ConnectorAuthentication, ConnectorAuthenticationMap, +}; + +#[derive(ValueEnum, Clone, Copy)] +pub enum Module { + Connector, + Users, +} #[derive(Parser)] #[command(version, about = "Postman collection runner using newman!", long_about = None)] -struct Args { +pub struct Args { /// Admin API Key of the environment #[arg(short, long)] admin_api_key: String, @@ -22,7 +31,10 @@ struct Args { base_url: String, /// Name of the connector #[arg(short, long)] - connector_name: String, + connector_name: Option, + /// Name of the module + #[arg(short, long)] + module_name: Option, /// Custom headers #[arg(short = 'H', long = "header")] custom_headers: Option>, @@ -38,6 +50,13 @@ struct Args { verbose: bool, } +impl Args { + /// Getter for the `module_name` field + pub fn get_module_name(&self) -> Option { + self.module_name + } +} + pub struct ReturnArgs { pub newman_command: Command, pub modified_file_paths: Vec>, @@ -82,10 +101,93 @@ where Ok(()) } -pub fn generate_newman_command() -> ReturnArgs { +// This function gives runner for connector or a module +pub fn generate_runner() -> Result { let args = Args::parse(); - let connector_name = args.connector_name; + match args.get_module_name() { + Some(Module::Users) => generate_newman_command_for_users(), + Some(Module::Connector) => generate_newman_command_for_connector(), + // Running connector tests when no module is passed to keep the previous test behavior same + None => generate_newman_command_for_connector(), + } +} + +pub fn generate_newman_command_for_users() -> Result { + let args = Args::parse(); + let base_url = args.base_url; + let admin_api_key = args.admin_api_key; + + let path = env::var("CONNECTOR_AUTH_FILE_PATH") + .with_context(|| "connector authentication file path not set")?; + + let authentication: ConnectorAuthentication = toml::from_str( + &fs::read_to_string(path) + .with_context(|| "connector authentication config file not found")?, + ) + .with_context(|| "connector authentication file path not set")?; + + let users_configs = authentication + .users + .with_context(|| "user configs not found in authentication file")?; + let collection_path = get_collection_path("users"); + + let mut newman_command = Command::new("newman"); + newman_command.args(["run", &collection_path]); + newman_command.args(["--env-var", &format!("admin_api_key={admin_api_key}")]); + newman_command.args(["--env-var", &format!("baseUrl={base_url}")]); + newman_command.args([ + "--env-var", + &format!("user_email={}", users_configs.user_email), + ]); + newman_command.args([ + "--env-var", + &format!( + "user_base_email_for_signup={}", + users_configs.user_base_email_for_signup + ), + ]); + newman_command.args([ + "--env-var", + &format!( + "user_domain_for_signup={}", + users_configs.user_domain_for_signup + ), + ]); + newman_command.args([ + "--env-var", + &format!("user_password={}", users_configs.user_password), + ]); + newman_command.args([ + "--env-var", + &format!("wrong_password={}", users_configs.wrong_password), + ]); + + newman_command.args([ + "--delay-request", + format!("{}", &args.delay_request).as_str(), + ]); + + newman_command.arg("--color").arg("on"); + + if args.verbose { + newman_command.arg("--verbose"); + } + + Ok(ReturnArgs { + newman_command, + modified_file_paths: vec![], + collection_path, + }) +} + +pub fn generate_newman_command_for_connector() -> Result { + let args = Args::parse(); + + let connector_name = args + .connector_name + .with_context(|| "invalid parameters: connector/module name not found in arguments")?; + let base_url = args.base_url; let admin_api_key = args.admin_api_key; @@ -216,11 +318,11 @@ pub fn generate_newman_command() -> ReturnArgs { newman_command.arg("--verbose"); } - ReturnArgs { + Ok(ReturnArgs { newman_command, modified_file_paths: vec![modified_collection_file_paths, custom_header_exist], collection_path, - } + }) } pub fn check_for_custom_headers(headers: Option>, path: &str) -> Option { diff --git a/postman/collection-dir/users/.event.meta.json b/postman/collection-dir/users/.event.meta.json new file mode 100644 index 0000000000..2df9d47d93 --- /dev/null +++ b/postman/collection-dir/users/.event.meta.json @@ -0,0 +1,6 @@ +{ + "eventOrder": [ + "event.prerequest.js", + "event.test.js" + ] +} diff --git a/postman/collection-dir/users/.info.json b/postman/collection-dir/users/.info.json new file mode 100644 index 0000000000..68f1e83b8e --- /dev/null +++ b/postman/collection-dir/users/.info.json @@ -0,0 +1,9 @@ +{ + "info": { + "_postman_id": "b5b40c9a-7e58-42c7-8b89-0adb208c45c9", + "name": "users", + "description": "## Get started\n\nJuspay Router provides a collection of APIs that enable you to process and manage payments. Our APIs accept and return JSON in the HTTP body, and return standard HTTP response codes. \nYou can consume the APIs directly using your favorite HTTP/REST library. \nWe have a testing environment referred to \"sandbox\", which you can setup to test API calls without affecting production data.\n\n### Base URLs\n\nUse the following base URLs when making requests to the APIs:\n\n| Environment | Base URL |\n| --- | --- |\n| Sandbox | [https://sandbox.hyperswitch.io](https://sandbox.hyperswitch.io) |\n| Production | [https://router.juspay.io](https://router.juspay.io) |\n\n# Authentication\n\nWhen you sign up for an account, you are given a secret key (also referred as api-key). You may authenticate all API requests with Juspay server by providing the appropriate key in the request Authorization header. \nNever share your secret api keys. Keep them guarded and secure.\n\nContact Support: \nName: Juspay Support \nEmail: [support@juspay.in](mailto:support@juspay.in)", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "26710321" + } +} diff --git a/postman/collection-dir/users/.meta.json b/postman/collection-dir/users/.meta.json new file mode 100644 index 0000000000..91b6a65c5b --- /dev/null +++ b/postman/collection-dir/users/.meta.json @@ -0,0 +1,6 @@ +{ + "childrenOrder": [ + "Health check", + "Flow Testcases" + ] +} diff --git a/postman/collection-dir/users/.variable.json b/postman/collection-dir/users/.variable.json new file mode 100644 index 0000000000..fba5b17b2f --- /dev/null +++ b/postman/collection-dir/users/.variable.json @@ -0,0 +1,126 @@ +{ + "variable": [ + { + "key": "baseUrl", + "value": "", + "type": "string" + }, + { + "key": "admin_api_key", + "value": "", + "type": "string" + }, + { + "key": "api_key", + "value": "", + "type": "string" + }, + { + "key": "merchant_id", + "value": "" + }, + { + "key": "payment_id", + "value": "" + }, + { + "key": "customer_id", + "value": "" + }, + { + "key": "mandate_id", + "value": "" + }, + { + "key": "payment_method_id", + "value": "" + }, + { + "key": "refund_id", + "value": "" + }, + { + "key": "merchant_connector_id", + "value": "" + }, + { + "key": "client_secret", + "value": "", + "type": "string" + }, + { + "key": "connector_api_key", + "value": "", + "type": "string" + }, + { + "key": "publishable_key", + "value": "", + "type": "string" + }, + { + "key": "api_key_id", + "value": "", + "type": "string" + }, + { + "key": "payment_token", + "value": "" + }, + { + "key": "gateway_merchant_id", + "value": "", + "type": "string" + }, + { + "key": "certificate", + "value": "", + "type": "string" + }, + { + "key": "certificate_keys", + "value": "", + "type": "string" + }, + { + "key": "connector_api_secret", + "value": "", + "type": "string" + }, + { + "key": "connector_key1", + "value": "", + "type": "string" + }, + { + "key": "connector_key2", + "value": "", + "type": "string" + }, + { + "key": "user_email", + "value": "", + "type": "string" + }, + { + "key": "user_password", + "value": "", + "type": "string" + }, + { + "key": "wrong_password", + "value": "", + "type": "string" + }, + { + "key": "user_base_email_for_signup", + "value": "", + "type": "string" + }, + { + "key": "user_domain_for_signup", + "value": "", + "type": "string" + } + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/.meta.json b/postman/collection-dir/users/Flow Testcases/.meta.json new file mode 100644 index 0000000000..3e649dae4e --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/.meta.json @@ -0,0 +1,6 @@ +{ + "childrenOrder": [ + "Sign Up", + "Sign In" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/.meta.json b/postman/collection-dir/users/Flow Testcases/Sign In/.meta.json new file mode 100644 index 0000000000..84ed2cb949 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/.meta.json @@ -0,0 +1,8 @@ +{ + "childrenOrder": [ + "Signin", + "Signin Wrong", + "Signin Token Only", + "Signin Token Only Wrong" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/.event.meta.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/.event.meta.json new file mode 100644 index 0000000000..688c85746e --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/.event.meta.json @@ -0,0 +1,5 @@ +{ + "eventOrder": [ + "event.test.js" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/event.test.js b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/event.test.js new file mode 100644 index 0000000000..16fca64a14 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/event.test.js @@ -0,0 +1,16 @@ +// Validate status 4xx +pm.test("[POST]::/user/v2/signin?token_only=true - Status code is 401", function () { + pm.response.to.have.status(401); +}); + +// Validate if response header has matching content-type +pm.test("[POST]::user/v2/signin?token_only=true - Content-Type is application/json", function () { + pm.expect(pm.response.headers.get("Content-Type")).to.include( + "application/json", + ); +}); + +// Validate if response has JSON Body +pm.test("[POST]::user/v2/signin?token_only=true - Response has JSON Body", function () { + pm.response.to.have.jsonBody(); +}); \ No newline at end of file diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/request.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/request.json new file mode 100644 index 0000000000..7fee4c465c --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/request.json @@ -0,0 +1,37 @@ +{ + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw_json_formatted": { + "email": "{{user_email}}", + "password": "{{wrong_password}}" + } + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin?token_only=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ], + "query": [ + { + "key": "token_only", + "value": "true" + } + ] + } +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/response.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only Wrong/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/.event.meta.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/.event.meta.json new file mode 100644 index 0000000000..688c85746e --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/.event.meta.json @@ -0,0 +1,5 @@ +{ + "eventOrder": [ + "event.test.js" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/event.test.js b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/event.test.js new file mode 100644 index 0000000000..a8b3658e5f --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/event.test.js @@ -0,0 +1,23 @@ +// Validate status 2xx +pm.test("[POST]::user/v2/signin?token_only=true - Status code is 2xx", function () { + pm.response.to.be.success; +}); + +// Validate if response header has matching content-type +pm.test("[POST]::user/v2/signin?token_only=true - Content-Type is application/json", function () { + pm.expect(pm.response.headers.get("Content-Type")).to.include( + "application/json", + ); +}); + +// Validate if response has JSON Body +pm.test("[POST]::user/v2/signin?token_only=true - Response has JSON Body", function () { + pm.response.to.have.jsonBody(); +}); + +// Validate specific JSON response content +pm.test("[POST]::user/v2/signin?token_only=true - Response contains token", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData).to.have.property("token"); + pm.expect(jsonData.token).to.be.a("string").and.to.not.be.empty; +}); \ No newline at end of file diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/request.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/request.json new file mode 100644 index 0000000000..62028501a5 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/request.json @@ -0,0 +1,37 @@ +{ + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw_json_formatted": { + "email": "{{user_email}}", + "password": "{{user_password}}" + } + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin?token_only=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ], + "query": [ + { + "key": "token_only", + "value": "true" + } + ] + } +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/response.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Token Only/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/.event.meta.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/.event.meta.json new file mode 100644 index 0000000000..688c85746e --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/.event.meta.json @@ -0,0 +1,5 @@ +{ + "eventOrder": [ + "event.test.js" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/event.test.js b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/event.test.js new file mode 100644 index 0000000000..e0149290da --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/event.test.js @@ -0,0 +1,16 @@ +// Validate status code is 4xx Bad Request +pm.test("[POST]::/user/v2/signin - Status code is 401", function () { + pm.response.to.have.status(401); +}); + +// Validate if response header has matching content-type +pm.test("[POST]::/user/v2/signin - Content-Type is application/json", function () { + pm.expect(pm.response.headers.get("Content-Type")).to.include( + "application/json", + ); +}); + +// Validate if response has JSON Body +pm.test("[POST]::/user/v2/signin - Response has JSON Body", function () { + pm.response.to.have.jsonBody(); +}); \ No newline at end of file diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/request.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/request.json new file mode 100644 index 0000000000..775b0972d5 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/request.json @@ -0,0 +1,31 @@ +{ + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw_json_formatted": { + "email": "{{user_email}}", + "password": "{{wrong_password}}" + } + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ] + } +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/response.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin Wrong/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin/.event.meta.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/.event.meta.json new file mode 100644 index 0000000000..4ac527d834 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/.event.meta.json @@ -0,0 +1,6 @@ +{ + "eventOrder": [ + "event.test.js", + "event.prerequest.js" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin/event.prerequest.js b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/event.prerequest.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin/event.test.js b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/event.test.js new file mode 100644 index 0000000000..174cbd8e5e --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/event.test.js @@ -0,0 +1,23 @@ +// Validate status 2xx +pm.test("[POST]::/user/v2/signin - Status code is 2xx", function () { + pm.response.to.be.success; +}); + +// Validate if response header has matching content-type +pm.test("[POST]::/user/v2/signin - Content-Type is application/json", function () { + pm.expect(pm.response.headers.get("Content-Type")).to.include( + "application/json", + ); +}); + +// Validate if response has JSON Body +pm.test("[POST]::/user/v2/signin - Response has JSON Body", function () { + pm.response.to.have.jsonBody(); +}); + +// Validate specific JSON response content +pm.test("[POST]::/user/v2/signin - Response contains token", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData).to.have.property("token"); + pm.expect(jsonData.token).to.be.a("string").and.to.not.be.empty; +}); \ No newline at end of file diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin/request.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/request.json new file mode 100644 index 0000000000..1d23f6e965 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/request.json @@ -0,0 +1,31 @@ +{ + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw_json_formatted": { + "email": "{{user_email}}", + "password": "{{user_password}}" + } + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ] + } +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign In/Signin/response.json b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign In/Signin/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/.meta.json b/postman/collection-dir/users/Flow Testcases/Sign Up/.meta.json new file mode 100644 index 0000000000..07d803fb1c --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/.meta.json @@ -0,0 +1,5 @@ +{ + "childrenOrder": [ + "Connect Account" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/.event.meta.json b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/.event.meta.json new file mode 100644 index 0000000000..4ac527d834 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/.event.meta.json @@ -0,0 +1,6 @@ +{ + "eventOrder": [ + "event.test.js", + "event.prerequest.js" + ] +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.prerequest.js b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.prerequest.js new file mode 100644 index 0000000000..7f16342a8a --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.prerequest.js @@ -0,0 +1,8 @@ + +var baseEmail = pm.environment.get('user_base_email_for_signup'); +var emailDomain = pm.environment.get("user_domain_for_signup"); + +// Generate a unique email address +var uniqueEmail = baseEmail + new Date().getTime() + emailDomain; +// Set the unique email address as an environment variable +pm.environment.set('unique_email', uniqueEmail); diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.test.js b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.test.js new file mode 100644 index 0000000000..6dbed06b0f --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/event.test.js @@ -0,0 +1,23 @@ +// Validate status 2xx +pm.test("[POST]::/user/connect_account - Status code is 2xx", function () { + pm.response.to.be.success; +}); + +// Validate if response header has matching content-type +pm.test("[POST]::/user/connect_account - Content-Type is application/json", function () { + pm.expect(pm.response.headers.get("Content-Type")).to.include( + "application/json", + ); +}); + +// Validate if response has JSON Body +pm.test("[POST]::/user/connect_account - Response has JSON Body", function () { + pm.response.to.have.jsonBody(); +}); + +// Validate specific JSON response content +pm.test("[POST]::/user/connect_account - Response contains is_email_sent", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData).to.have.property("is_email_sent"); + pm.expect(jsonData.is_email_sent).to.be.true; +}); diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/request.json b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/request.json new file mode 100644 index 0000000000..d5f2433ad7 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/request.json @@ -0,0 +1,29 @@ +{ + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw_json_formatted": { + "email": "{{unique_email}}" + } + }, + "url": { + "raw": "{{baseUrl}}/user/connect_account", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "connect_account" + ] + } +} diff --git a/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/response.json b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Flow Testcases/Sign Up/Connect Account/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/Health check/.meta.json b/postman/collection-dir/users/Health check/.meta.json new file mode 100644 index 0000000000..66ee7e50ca --- /dev/null +++ b/postman/collection-dir/users/Health check/.meta.json @@ -0,0 +1,5 @@ +{ + "childrenOrder": [ + "New Request" + ] +} diff --git a/postman/collection-dir/users/Health check/New Request/.event.meta.json b/postman/collection-dir/users/Health check/New Request/.event.meta.json new file mode 100644 index 0000000000..688c85746e --- /dev/null +++ b/postman/collection-dir/users/Health check/New Request/.event.meta.json @@ -0,0 +1,5 @@ +{ + "eventOrder": [ + "event.test.js" + ] +} diff --git a/postman/collection-dir/users/Health check/New Request/event.test.js b/postman/collection-dir/users/Health check/New Request/event.test.js new file mode 100644 index 0000000000..5e5505dfa3 --- /dev/null +++ b/postman/collection-dir/users/Health check/New Request/event.test.js @@ -0,0 +1,4 @@ +// Validate status 2xx +pm.test("[POST]::/health - Status code is 2xx", function () { + pm.response.to.be.success; +}); diff --git a/postman/collection-dir/users/Health check/New Request/request.json b/postman/collection-dir/users/Health check/New Request/request.json new file mode 100644 index 0000000000..4e1e0a0d9e --- /dev/null +++ b/postman/collection-dir/users/Health check/New Request/request.json @@ -0,0 +1,13 @@ +{ + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/health", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "health" + ] + } +} diff --git a/postman/collection-dir/users/Health check/New Request/response.json b/postman/collection-dir/users/Health check/New Request/response.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/postman/collection-dir/users/Health check/New Request/response.json @@ -0,0 +1 @@ +[] diff --git a/postman/collection-dir/users/event.prerequest.js b/postman/collection-dir/users/event.prerequest.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/postman/collection-dir/users/event.test.js b/postman/collection-dir/users/event.test.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/postman/collection-json/users.postman_collection.json b/postman/collection-json/users.postman_collection.json new file mode 100644 index 0000000000..943d37d22d --- /dev/null +++ b/postman/collection-json/users.postman_collection.json @@ -0,0 +1,556 @@ +{ + "event": [ + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "test", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "item": [ + { + "name": "Health check", + "item": [ + { + "name": "New Request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status 2xx", + "pm.test(\"[POST]::/health - Status code is 2xx\", function () {", + " pm.response.to.be.success;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{baseUrl}}/health", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "health" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Flow Testcases", + "item": [ + { + "name": "Sign Up", + "item": [ + { + "name": "Connect Account", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status 2xx", + "pm.test(\"[POST]::/user/connect_account - Status code is 2xx\", function () {", + " pm.response.to.be.success;", + "});", + "", + "// Validate if response header has matching content-type", + "pm.test(\"[POST]::/user/connect_account - Content-Type is application/json\", function () {", + " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(", + " \"application/json\",", + " );", + "});", + "", + "// Validate if response has JSON Body", + "pm.test(\"[POST]::/user/connect_account - Response has JSON Body\", function () {", + " pm.response.to.have.jsonBody();", + "});", + "", + "// Validate specific JSON response content", + "pm.test(\"[POST]::/user/connect_account - Response contains is_email_sent\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property(\"is_email_sent\");", + " pm.expect(jsonData.is_email_sent).to.be.true;", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "", + "var baseEmail = pm.environment.get('user_base_email_for_signup');", + "var emailDomain = pm.environment.get(\"user_domain_for_signup\");", + "", + "// Generate a unique email address", + "var uniqueEmail = baseEmail + new Date().getTime() + emailDomain;", + "// Set the unique email address as an environment variable", + "pm.environment.set('unique_email', uniqueEmail);", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{unique_email}}\"}" + }, + "url": { + "raw": "{{baseUrl}}/user/connect_account", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "connect_account" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Sign In", + "item": [ + { + "name": "Signin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status 2xx", + "pm.test(\"[POST]::/user/v2/signin - Status code is 2xx\", function () {", + " pm.response.to.be.success;", + "});", + "", + "// Validate if response header has matching content-type", + "pm.test(\"[POST]::/user/v2/signin - Content-Type is application/json\", function () {", + " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(", + " \"application/json\",", + " );", + "});", + "", + "// Validate if response has JSON Body", + "pm.test(\"[POST]::/user/v2/signin - Response has JSON Body\", function () {", + " pm.response.to.have.jsonBody();", + "});", + "", + "// Validate specific JSON response content", + "pm.test(\"[POST]::/user/v2/signin - Response contains token\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property(\"token\");", + " pm.expect(jsonData.token).to.be.a(\"string\").and.to.not.be.empty;", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{user_email}}\",\"password\":\"{{user_password}}\"}" + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ] + } + }, + "response": [] + }, + { + "name": "Signin Wrong", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status code is 4xx Bad Request", + "pm.test(\"[POST]::/user/v2/signin - Status code is 401\", function () {", + " pm.response.to.have.status(401);", + "});", + "", + "// Validate if response header has matching content-type", + "pm.test(\"[POST]::/user/v2/signin - Content-Type is application/json\", function () {", + " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(", + " \"application/json\",", + " );", + "});", + "", + "// Validate if response has JSON Body", + "pm.test(\"[POST]::/user/v2/signin - Response has JSON Body\", function () {", + " pm.response.to.have.jsonBody();", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{user_email}}\",\"password\":\"{{wrong_password}}\"}" + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ] + } + }, + "response": [] + }, + { + "name": "Signin Token Only", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status 2xx", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Status code is 2xx\", function () {", + " pm.response.to.be.success;", + "});", + "", + "// Validate if response header has matching content-type", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Content-Type is application/json\", function () {", + " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(", + " \"application/json\",", + " );", + "});", + "", + "// Validate if response has JSON Body", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Response has JSON Body\", function () {", + " pm.response.to.have.jsonBody();", + "});", + "", + "// Validate specific JSON response content", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Response contains token\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property(\"token\");", + " pm.expect(jsonData.token).to.be.a(\"string\").and.to.not.be.empty;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{user_email}}\",\"password\":\"{{user_password}}\"}" + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin?token_only=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ], + "query": [ + { + "key": "token_only", + "value": "true" + } + ] + } + }, + "response": [] + }, + { + "name": "Signin Token Only Wrong", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Validate status 4xx", + "pm.test(\"[POST]::/user/v2/signin?token_only=true - Status code is 401\", function () {", + " pm.response.to.have.status(401);", + "});", + "", + "// Validate if response header has matching content-type", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Content-Type is application/json\", function () {", + " pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(", + " \"application/json\",", + " );", + "});", + "", + "// Validate if response has JSON Body", + "pm.test(\"[POST]::user/v2/signin?token_only=true - Response has JSON Body\", function () {", + " pm.response.to.have.jsonBody();", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Cookie", + "value": "Cookie_1=value" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{user_email}}\",\"password\":\"{{wrong_password}}\"}" + }, + "url": { + "raw": "{{baseUrl}}/user/v2/signin?token_only=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "user", + "v2", + "signin" + ], + "query": [ + { + "key": "token_only", + "value": "true" + } + ] + } + }, + "response": [] + } + ] + } + ] + } + ], + "info": { + "_postman_id": "b5b40c9a-7e58-42c7-8b89-0adb208c45c9", + "name": "users", + "description": "## Get started\n\nJuspay Router provides a collection of APIs that enable you to process and manage payments. Our APIs accept and return JSON in the HTTP body, and return standard HTTP response codes. \nYou can consume the APIs directly using your favorite HTTP/REST library. \nWe have a testing environment referred to \"sandbox\", which you can setup to test API calls without affecting production data.\n\n### Base URLs\n\nUse the following base URLs when making requests to the APIs:\n\n| Environment | Base URL |\n| --- | --- |\n| Sandbox | [https://sandbox.hyperswitch.io](https://sandbox.hyperswitch.io) |\n| Production | [https://router.juspay.io](https://router.juspay.io) |\n\n# Authentication\n\nWhen you sign up for an account, you are given a secret key (also referred as api-key). You may authenticate all API requests with Juspay server by providing the appropriate key in the request Authorization header. \nNever share your secret api keys. Keep them guarded and secure.\n\nContact Support: \nName: Juspay Support \nEmail: [support@juspay.in](mailto:support@juspay.in)", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "26710321" + }, + "variable": [ + { + "key": "baseUrl", + "value": "", + "type": "string" + }, + { + "key": "admin_api_key", + "value": "", + "type": "string" + }, + { + "key": "api_key", + "value": "", + "type": "string" + }, + { + "key": "merchant_id", + "value": "" + }, + { + "key": "payment_id", + "value": "" + }, + { + "key": "customer_id", + "value": "" + }, + { + "key": "mandate_id", + "value": "" + }, + { + "key": "payment_method_id", + "value": "" + }, + { + "key": "refund_id", + "value": "" + }, + { + "key": "merchant_connector_id", + "value": "" + }, + { + "key": "client_secret", + "value": "", + "type": "string" + }, + { + "key": "connector_api_key", + "value": "", + "type": "string" + }, + { + "key": "publishable_key", + "value": "", + "type": "string" + }, + { + "key": "api_key_id", + "value": "", + "type": "string" + }, + { + "key": "payment_token", + "value": "" + }, + { + "key": "gateway_merchant_id", + "value": "", + "type": "string" + }, + { + "key": "certificate", + "value": "", + "type": "string" + }, + { + "key": "certificate_keys", + "value": "", + "type": "string" + }, + { + "key": "connector_api_secret", + "value": "", + "type": "string" + }, + { + "key": "connector_key1", + "value": "", + "type": "string" + }, + { + "key": "connector_key2", + "value": "", + "type": "string" + }, + { + "key": "user_email", + "value": "", + "type": "string" + }, + { + "key": "user_password", + "value": "", + "type": "string" + }, + { + "key": "wrong_password", + "value": "", + "type": "string" + }, + { + "key": "user_base_email_for_signup", + "value": "", + "type": "string" + }, + { + "key": "user_domain_for_signup", + "value": "", + "type": "string" + } + ] +}