Files
freeCodeCamp/curriculum/challenges/russian/05-apis-and-microservices/apis-and-microservices-projects/timestamp-microservice.russian.md

3.5 KiB
Raw Blame History

id, title, challengeType, isRequired, forumTopicId, localeTitle
id title challengeType isRequired forumTopicId localeTitle
bd7158d8c443edefaeb5bdef Timestamp Microservice 4 true 301508 Временная метка Микросервис

Description

Создайте полноценное приложение JavaScript, функционально похожее на это: https://curse-arrow.glitch.me/ . Работа над этим проектом потребует от вас написания кода на Glitch для нашего стартового проекта. После завершения этого проекта вы можете скопировать общедоступный URL-адрес сбоя (на главную страницу вашего приложения) на этот экран, чтобы протестировать его! При желании вы можете написать свой проект на другой платформе, но он должен быть открыт для нашего тестирования. Запустите этот проект на Glitch по этой ссылке или клонируйте этот репозиторий на GitHub! Если вы используете Glitch, не забудьте сохранить ссылку на ваш проект в безопасном месте!

Instructions

Tests

tests:
  - text: It should handle a valid date, and return the correct unix timestamp
    testString: getUserInput => $.get(getUserInput('url') + '/api/timestamp/2016-12-25').then(data => { assert.equal(data.unix, 1482624000000, 'Should be a valid unix timestamp'); }, xhr => { throw new Error(xhr.responseText); })
  - text: It should handle a valid date, and return the correct UTC string
    testString: getUserInput => $.get(getUserInput('url')+ '/api/timestamp/2016-12-25').then(data => { assert.equal(data.utc, 'Sun, 25 Dec 2016 00:00:00 GMT', 'Should be a valid UTC date string'); }, xhr => { throw new Error(xhr.responseText); })
  - text: It should handle a valid unix date, and return the correct unix timestamp
    testString: getUserInput => $.get(getUserInput('url') + '/api/timestamp/1482624000000').then(data => { assert.equal(data.unix, 1482624000000) ;  }, xhr => { throw new Error(xhr.responseText); })
  - text: It should return the expected error message for an invalid date
    testString: getUserInput => $.get(getUserInput('url') + '/api/timestamp/this-is-not-a-date').then(data => { assert.equal(data.error.toLowerCase(), 'invalid date');}, xhr => { throw new Error(xhr.responseText); })
  - text: It should handle an empty date parameter, and return the current time in unix format
    testString: getUserInput => $.get(getUserInput('url') + '/api/timestamp').then(data => { var now = Date.now(); assert.approximately(data.unix, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })
  - text: It should handle an empty date parameter, and return the current time in UTC format
    testString: getUserInput => $.get(getUserInput('url') + '/api/timestamp').then(data => { var now = Date.now(); var serverTime = (new Date(data.utc)).getTime(); assert.approximately(serverTime, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })