API Testing : Check multi-timezone support

Verify that the API correctly handles multi-timezone support and returns the correct resources for each timezone.

Language: Java

Framework: Rest assured

copy
1/​/​Assumption: The API returns resources with timezone information2/​/​Assumption: The API supports multiple timezones.34import org.junit.Test;5import static io.restassured.RestAssured.*;6import static org.hamcrest.Matchers.*;78public class MultiTimeZoneAPITest {910 @Test11 public void testMultiTimeZoneSupport() {1213 /​/​Assumption: The API returns timezone information in ISO format14 String[] timezones = {"GMT", "EST", "PST"};1516 for(String timezone : timezones){17 given()18 .header("Content-Type", "application/​json")19 .header("Timezone", timezone)20 .when()21 .get("/​api/​resources")22 .then()23 .statusCode(200)24 .body("timezone", equalTo(timezone));25 } 26 }27 28 /​/​Uncomment below code to connect to remote client with desired capabilities29 /​*30 @Test31 public void testMultiTimeZoneSupportOnRemoteClient() {32 33 DesiredCapabilities capabilities = new DesiredCapabilities();34 capabilities.setCapability("browserName", "chrome");35 capabilities.setCapability("timezone", "GMT");36 capabilities.setCapability("version", "91.0");37 capabilities.setCapability("platformName", "Windows 10");38 39 RemoteWebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"),capabilities);40 41 /​/​replace "http:/​/​localhost:8080/​api/​resources" with the API URL of the application deployed in remote client42 driver.get("http:/​/​localhost:8080/​api/​resources"); 43 44 /​/​replace "GMT" with the expected timezone value45 assert driver.getPageSource().contains("GMT");4647 driver.quit(); 48 }49 */​50}

Language: Javascript

copy
1/​/​ Mocha and Chai.23/​/​ Assumptions: 4/​/​ - The API can handle GET requests to retrieve resources.5/​/​ - Each resource returned by the API contains a timezone attribute.6/​/​ - The API can handle timezone parameters in GET requests.7/​/​ - The API supports at least 3 timezones: Pacific, Eastern, and Central.89const chai = require('chai');10const expect = chai.expect;1112/​/​ Local driver setup13const url = 'http:/​/​localhost:3000'; /​/​ Replace with actual endpoint URL14const request = require('supertest')(url);1516/​/​ Uncomment the following code to connect to a remote client with desired capabilities.17/​/​ const webdriver = require('webdriverio');18/​/​ const options = {19/​/​ desiredCapabilities: {20/​/​ browserName: 'chrome',21/​/​ timezone: 'America/​Los_Angeles'22/​/​ }23/​/​ };24/​/​ const client = webdriver.remote(options);2526describe('API Testing', () => {27 describe('Multi-timezone support', () => {28 it('should return the correct resources for each timezone', (done) => {29 const pacificResource = { id: 1, name: 'Resource 1', timezone: 'America/​Los_Angeles' };30 const easternResource = { id: 2, name: 'Resource 2', timezone: 'America/​New_York' };31 const centralResource = { id: 3, name: 'Resource 3', timezone: 'America/​Chicago' };32 33 /​/​ GET resources for Pacific timezone34 request35 .get('/​resources?timezone=America/​Los_Angeles')36 .end((err, res) => {37 expect(err).to.be.null;38 expect(res.body).to.deep.include(pacificResource);39 40 /​/​ GET resources for Eastern timezone41 request42 .get('/​resources?timezone=America/​New_York')43 .end((err, res) => {44 expect(err).to.be.null;45 expect(res.body).to.deep.include(easternResource);46 47 /​/​ GET resources for Central timezone48 request49 .get('/​resources?timezone=America/​Chicago')50 .end((err, res) => {51 expect(err).to.be.null;52 expect(res.body).to.deep.include(centralResource);53 done();54 });55 });56 });57 });58 });59});

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing