All files / session ttl.js

16.21% Statements 6/37
100% Branches 0/0
0% Functions 0/1
16.21% Lines 6/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 381x 1x 1x                                                               1x 1x 1x  
import axios from 'axios';
 
const fetchTtl = token => {
    const requestOptions = {
        method: 'GET',
        url: '/api/auth/sessions/ttl',
        headers: {
            Accept: 'application/vnd.qpp.cms.gov.v1+json',
            'Content-Type': 'application/json',
            Authorization: `Bearer ${token}`
        },
        transformResponse: [
            function(response) {
                return JSON.parse(response).data;
            }
        ]
    };

    return axios(requestOptions).then(response => {
        let expiry;

        if (response && response.data) {
            if (response.data.hasOwnProperty('time_remaining')) {
                expiry = response.data.time_remaining;
            } else {
                // See https://tools.ietf.org/html/rfc7519
                // `expiry` is a NumericDate representing "seconds since the epoch"
                // and it needs to be milliseconds to get a JavaScript date from it.
                expiry = new Date(response.data.ttl * 1000);
            }
        }

        return expiry;
    });
};
 
export default fetchTtl;