test/unit/helpers.timezone.js
import test from 'ava';
import {
client,
Timezone,
} from '../../src';
test.before('start server', () => {
client.apiBaseUrl = 'https://somesite.Clinical6.com';
client.authToken = 'valid_token';
});
test.beforeEach((t) => {
client.cache = 'never';
client.authToken = 'valid_token';
t.context.storage = client.storageUtility;
client.timezone = new Timezone({});
t.context.timezoneJsonApi = {
id: 'etc/gmt+10.0__-10.0',
type: 'timezones',
attributes: {
name: 'Etc/GMT+10.0',
offset: -10,
region: 'Etc'
}
};
t.context.timezone = new Timezone(t.context.timezoneJsonApi);
});
/**
* @test {Timezone}
*/
test('[unit] Timezone should handle timezone data with a normal json format', (t) => {
const { timezoneJsonApi } = t.context;
const timezone = new Timezone({ data: timezoneJsonApi });
t.is(timezone.id, 'etc/gmt+10.0__-10.0');
t.is(timezone.type, 'timezones');
t.is(timezone.name, 'Etc/GMT+10.0');
t.is(timezone.offset, -10.0);
t.is(timezone.region, 'Etc');
});
/**
* @test {timezone}
*/
test('[unit] timezone should generate json api format when converted to string', (t) => {
const { timezoneJsonApi } = t.context;
let timezone = new Timezone({ data: timezoneJsonApi });
let json = timezone.toJSON();
t.deepEqual(json, timezoneJsonApi);
timezone = new Timezone({ data: timezoneJsonApi });
json = timezone.toJSON();
t.deepEqual(json, timezoneJsonApi);
});