@gameroom/kit
Version:
Node kit for the Gameroom API
105 lines (101 loc) • 3.68 kB
JavaScript
/* eslint eqeqeq: 0 */
const { faker } = require('@faker-js/faker'),
chai = require('chai')
const {
lib: { SecondsFrom1970 }
} = require('../../')
const should = chai.should()
describe('SecondsFrom1970', () => {
describe('new SecondsFrom1970()', () => {
it('should create a new SecondsFrom1970 with default values', () => {
const secondsFrom1970 = new SecondsFrom1970()
should.exist(secondsFrom1970)
})
})
describe('new SecondsFrom1970(date)', () => {
it('should create a new SecondsFrom1970 with provided value', () => {
const date = faker.date.past()
const secondsFrom1970 = new SecondsFrom1970(date)
should.exist(secondsFrom1970)
should.equal(date.getTime() * 0.001 == secondsFrom1970, true)
})
})
describe('new SecondsFrom1970(number)', () => {
it('should create a new SecondsFrom1970 with provided value', () => {
const number = Math.round(faker.date.past() / 1000)
const secondsFrom1970 = new SecondsFrom1970(number)
should.exist(secondsFrom1970)
should.equal(number == secondsFrom1970, true)
})
})
describe('new SecondsFrom1970(string)', () => {
it('should create a new SecondsFrom1970 with provided value', () => {
const date = faker.date.past()
const string = date.toISOString()
const secondsFrom1970 = new SecondsFrom1970(string)
should.exist(secondsFrom1970)
should.equal(date.getTime() * 0.001 == secondsFrom1970, true)
})
})
describe('SecondsFrom1970.equal(a, b)', () => {
it('should compare two SecondsFrom1970', () => {
const a = SecondsFrom1970.now()
let b = new SecondsFrom1970(a)
should.equal(a === b, false)
should.equal(SecondsFrom1970.equal(a, b), true)
b = new SecondsFrom1970(a.toNumber() + 100)
should.equal(SecondsFrom1970.equal(a, b), false)
})
})
describe('SecondsFrom1970.now()', () => {
it('should create a new SecondsFrom1970 with default value', () => {
const secondsFrom1970 = SecondsFrom1970.now()
should.exist(secondsFrom1970)
})
})
describe('secondsFrom1970.equals(b)', () => {
it('should compare this value with a provided value', () => {
const a = SecondsFrom1970.now()
let b = new SecondsFrom1970(a)
should.equal(a === b, false)
should.equal(a.equals(b), true)
b = new SecondsFrom1970(a.toNumber() + 100)
should.equal(a.equals(b), false)
})
})
describe('secondsFrom1970.toDate()', () => {
it('should create a new Date from SecondsFrom1970', () => {
const secondsFrom1970 = SecondsFrom1970.now()
const date = secondsFrom1970.toDate()
should.exist(date)
})
})
describe('secondsFrom1970.toLocaleDateString()', () => {
it('should return locale date string', () => {
const secondsFrom1970 = SecondsFrom1970.now()
const string = secondsFrom1970.toLocaleDateString()
should.exist(string)
})
})
describe('secondsFrom1970.toLocaleTimeString()', () => {
it('should return locale time string', () => {
const secondsFrom1970 = SecondsFrom1970.now()
const string = secondsFrom1970.toLocaleTimeString()
should.exist(string)
})
})
describe('secondsFrom1970.toNumber()', () => {
it('should return as a number', () => {
const secondsFrom1970 = SecondsFrom1970.now()
const number = secondsFrom1970.toNumber()
should.exist(number)
})
})
describe('secondsFrom1970.toTimestamp()', () => {
it('should return a timestamp', () => {
const secondsFrom1970 = SecondsFrom1970.now()
const string = secondsFrom1970.toTimestamp()
should.exist(string)
})
})
})