<commit_before>import commonRoutes from './routes';
import ENV from 'ilios/config/environment';
import { discoverEmberDataModels } from 'ember-cli-mirage';
import { createServer, Response } from 'miragejs';
import moment from 'moment';

const { apiVersion } = ENV;

export default function (config) {
  let finalConfig = {
    ...config,
    models: { ...discoverEmberDataModels(), ...config.models },
    routes() {
      this.timing = 100;
      this.namespace = '/';
      this.passthrough('/write-coverage');
      commonRoutes(this);
      this.post('auth/login', function (schema, request) {
        const errors = [];
        var attrs = JSON.parse(request.requestBody);
        if (!('username' in attrs) || !attrs.username) {
          errors.push('missingUsername');
        }
        if (!('password' in attrs) || !attrs.password) {
          errors.push('missingPassword');
        }
        const username = attrs.username.toLowerCase();
        if (errors.length === 0) {
          if (username === 'demo' && attrs.password === '<PASSWORD>') {
            const now = moment();
            const nextWeek = now.clone().add(1, 'week');
            const header = '{"alg":"none"}';
            const body = `{"iss": "ilios","aud": "ilios","iat": "${now.format(
              'X'
            )}","exp": "${nextWeek.format('X')}","user_id": 4136}`;

            const encodedData = window.btoa(header) + '.' + window.btoa(body) + '.';
            return {
              jwt: encodedData,
            };
          } else {
            errors.push('badCredentials');
          }
        }
        return new Response(400, {}, { errors: errors });
      });

      this.get('auth/logout', function () {
        return new Response(200);
      });

      this.get('auth/whoami', function () {
        return {
          userId: 4136,
        };
      });

      this.get('application/config', function () {
        return {
          config: {
            type: 'form',
            apiVersion,
            appVersion: '1.2.3',
          },
        };
        // return { config: {
        //   type: 'shibboleth',
        //   shibbolethLoginUrl: '/fakeshiblogin'
        // }};
      });

      this.get('auth/token', function () {
        //un comment to send unauthenticated user data
        // return {
        //   jwt: null
        // };
        const now = moment();
        const nextWeek = now.clone().add(1, 'week');
        const header = '{"alg":"none"}';
        const body = `{"iss": "ilios","aud": "ilios","iat": "${now.format(
          'X'
        )}","exp": "${nextWeek.format('X')}","user_id": 4136}`;

        const encodedData = window.btoa(header) + '.' + window.btoa(body) + '.';
        return {
          jwt: encodedData,
        };
      });
<commit_msg>Replace moment with luxon in test<commit_after>import commonRoutes from './routes';
import ENV from 'ilios/config/environment';
import { discoverEmberDataModels } from 'ember-cli-mirage';
import { createServer, Response } from 'miragejs';
import { DateTime } from 'luxon';

const { apiVersion } = ENV;

export default function (config) {
  let finalConfig = {
    ...config,
    models: { ...discoverEmberDataModels(), ...config.models },
    routes() {
      this.timing = 100;
      this.namespace = '/';
      this.passthrough('/write-coverage');
      commonRoutes(this);
      this.post('auth/login', function (schema, request) {
        const errors = [];
        var attrs = JSON.parse(request.requestBody);
        if (!('username' in attrs) || !attrs.username) {
          errors.push('missingUsername');
        }
        if (!('password' in attrs) || !attrs.password) {
          errors.push('missingPassword');
        }
        const username = attrs.username.toLowerCase();
        if (errors.length === 0) {
          if (username === 'demo' && attrs.password === '<PASSWORD>') {
            const now = DateTime.now();
            const nextWeek = now.plus({ weeks: 1 });
            const header = '{"alg":"none"}';
            const body = `{"iss": "ilios","aud": "ilios","iat": "${now.toUnixInteger()}","exp": "${nextWeek.toUnixInteger()}","user_id": 4136}`;

            const encodedData = window.btoa(header) + '.' + window.btoa(body) + '.';
            return {
              jwt: encodedData,
            };
          } else {
            errors.push('badCredentials');
          }
        }
        return new Response(400, {}, { errors: errors });
      });

      this.get('auth/logout', function () {
        return new Response(200);
      });

      this.get('auth/whoami', function () {
        return {
          userId: 4136,
        };
      });

      this.get('application/config', function () {
        return {
          config: {
            type: 'form',
            apiVersion,
            appVersion: '1.2.3',
          },
        };
        // return { config: {
        //   type: 'shibboleth',
        //   shibbolethLoginUrl: '/fakeshiblogin'
        // }};
      });

      this.get('auth/token', function () {
        //un comment to send unauthenticated user data
        // return {
        //   jwt: null
        // };
        const now = DateTime.now();
        const nextWeek = now.plus({ weeks: 1 });
        const header = '{"alg":"none"}';
        const body = `{"iss": "ilios","aud": "ilios","iat": "${now.toUnixInteger()}","exp": "${nextWeek.toUnixInteger()}","user_id": 4136}`;

        const encodedData = window.btoa(header) + '.' + window.btoa(body) + '.';
        return {
          jwt: encodedData,
        };
      });

{'fraction_non_alphanumeric': 0.17513009151265027, 'fraction_numerical': 0.009689574735331061, 'mean_word_length': 1.9122257053291536, 'pattern_counts': {'":': 24, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300283', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1645, 'n_words': 343}