<commit_before>{AuthModel} = require './authModel'
{TestUtil}  = require '../util/testUtil'

settings = {
  dataPath: __dirname + "/../data_test"
  email: {
    from: "<NAME> <<EMAIL>>"
    user: "hectorjcorrea"
    password: "<PASSWORD>"
    host: "smtp.gmail.com"
    ssl: true
  },
  adminUserEmail: "<EMAIL>"
  loginKeyValidHours: 2
  rootUrl: "http://hectorcorrea.com"
}


# Notice that these tests run synchronously

test = new TestUtil("autModelTest.EmptyRequest", true)
model = new AuthModel(settings)
model.clearAuthData()

req = {
  cookies: {}
}

test.passIf model.isAuthenticated(req) is false, "empty req/empty data"


data = model.generateLoginKey()
test.passIf data.loginKey?, 'generate loginKey'


data = model.generateAuthToken()
test.passIf data.authToken?, 'generate authToken'


req = {
  cookies: {
    session: {
      authToken: data.authToken
    }
  }
}
test.passIf model.isAuthenticated(req), "authenticated request"

<commit_msg>Updated unit tests to use proper settings file<commit_after>{AuthModel} = require './authModel'
{TestUtil}  = require '../util/testUtil'
settings = require '../util/settings'

testSettings = settings.load 'settings.test.json', __dirname

# settings = {
#   dataPath: __dirname + "/../data_test"
#   email: {
#     from: "<NAME> <<EMAIL>>"
#     user: "hectorjcorrea"
#     password: "<PASSWORD>"
#     host: "smtp.gmail.com"
#     ssl: true
#   },
#   adminUserEmail: "<EMAIL>"
#   loginKeyValidHours: 2
#   rootUrl: "http://hectorcorrea.com"
# }


# Notice that these tests run synchronously

test = new TestUtil("autModelTest.EmptyRequest", true)
model = new AuthModel(testSettings)
model.clearAuthData()

req = {
  cookies: {}
}

test.passIf model.isAuthenticated(req) is false, "empty req/empty data"


data = model.generateLoginKey()
test.passIf data.loginKey?, 'generate loginKey'


data = model.generateAuthToken()
test.passIf data.authToken?, 'generate authToken'


req = {
  cookies: {
    session: {
      authToken: data.authToken
    }
  }
}
test.passIf model.isAuthenticated(req), "authenticated request"


{'fraction_non_alphanumeric': 0.14409638554216866, 'fraction_numerical': 0.0009638554216867469, 'mean_word_length': 3.942857142857143, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5420246', 'n_tokens_mistral': 714, 'n_tokens_neox': 700, 'n_words': 158}