<commit_before>/* eslint-env node, mocha */
"use strict";

var Promise = require('bluebird');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
var expect = chai.expect;

var Storage = require('../classes/Storage.js');
var Context = require('../classes/Context.js');

describe('Context', function() {
  var storage;
  var temporary = {};
  
  var regularUser1;
  var regularUser2;
  var adminUser;

  before(function() {
    storage = new Storage({
      modelsDir: 'test/models'
    });
    let promises = [];
    let query;
    let promise;
    query = `{user:createUser(name: "Alice", mail: "<EMAIL>") { id }}`;
    promise = storage.query(query).then((result) => {
      regularUser1 = result.user.id;
    });
    promises.push(promise);
    query = `{user:createUser(name: "Bob", mail: "<EMAIL>") { id }}`;
    promise = storage.query(query).then((result) => {
      regularUser2 = result.user.id;
    });
    promises.push(promise);
    query = `{user:createUser(name: "Chris", mail: "<EMAIL>", admin: {}) { id }}`;
    promise = storage.query(query).then((result) => {
      adminUser = result.user.id;
    });
    promises.push(promise);
    return Promise.all(promises);
  });

  after(function() {
    return Promise.all([
      storage.query('{deleteUser(id:?)}', [regularUser1]),
      storage.query('{deleteUser(id:?)}', [regularUser2]),
      storage.query('{deleteUser(id:?)}', [adminUser])
    ]);
  });

  it('can get current user profile', function() {
    let context = new Context();
    context.setUser({id: regularUser1});
    let query = `{
      User {
        id
        name
      }
    }`;
    return storage.query(query, context).then((result) => {
      expect(result.User).to.have.property('id', regularUser1);
      expect(result.User).to.have.property('name', 'Alice');
    });
  });

  it('can create post as owner', function() {
    let context = new Context();
    context.setUser({id: regularUser1});
    let query = `{
      createPost(owner:?) {
        id
      }
    }`;
    let args = [regularUser1];
    return storage.query(query, context, args).then((result) => {
      expect(result.createPost).to.have.property('id');
      temporary = {id: result.createPost.id};
    });
  });

  it('can create post as owner', function() {
    let context = new Context();
    context.setUser({id: regularUser1});
    let query = `{
      createPost(owner:?) {
        id
      }
    }`;
    let args = [regularUser1];
    return storage.query(query, context, args).then((result) => {
      expect(result.createPost).to.have.property('id');
      temporary = {id: result.createPost.id};
    });
  });

  it('can read post as owner', function() {<commit_msg>Remove duplicate testcase<commit_after>/* eslint-env node, mocha */
"use strict";

var Promise = require('bluebird');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
var expect = chai.expect;

var Storage = require('../classes/Storage.js');
var Context = require('../classes/Context.js');

describe('Context', function() {
  var storage;
  var temporary = {};
  
  var regularUser1;
  var regularUser2;
  var adminUser;

  before(function() {
    storage = new Storage({
      modelsDir: 'test/models'
    });
    let promises = [];
    let query;
    let promise;
    query = `{user:createUser(name: "Alice", mail: "<EMAIL>") { id }}`;
    promise = storage.query(query).then((result) => {
      regularUser1 = result.user.id;
    });
    promises.push(promise);
    query = `{user:createUser(name: "Bob", mail: "<EMAIL>") { id }}`;
    promise = storage.query(query).then((result) => {
      regularUser2 = result.user.id;
    });
    promises.push(promise);
    query = `{user:createUser(name: "Chris", mail: "<EMAIL>", admin: {}) { id }}`;
    promise = storage.query(query).then((result) => {
      adminUser = result.user.id;
    });
    promises.push(promise);
    return Promise.all(promises);
  });

  after(function() {
    return Promise.all([
      storage.query('{deleteUser(id:?)}', [regularUser1]),
      storage.query('{deleteUser(id:?)}', [regularUser2]),
      storage.query('{deleteUser(id:?)}', [adminUser])
    ]);
  });

  it('can get current user profile', function() {
    let context = new Context();
    context.setUser({id: regularUser1});
    let query = `{
      User {
        id
        name
      }
    }`;
    return storage.query(query, context).then((result) => {
      expect(result.User).to.have.property('id', regularUser1);
      expect(result.User).to.have.property('name', 'Alice');
    });
  });

  it('can create post as user', function() {
    let context = new Context();
    context.setUser({id: regularUser1});
    let query = `{
      createPost(owner:?) {
        id
      }
    }`;
    let args = [regularUser1];
    return storage.query(query, context, args).then((result) => {
      expect(result.createPost).to.have.property('id');
      temporary = {id: result.createPost.id};
    });
  });

  it('can read post as owner', function() {
{'fraction_non_alphanumeric': 0.18517790446235502, 'fraction_numerical': 0.004324749361116572, 'mean_word_length': 3.0999194198227236, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, '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': '756297', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1655, 'n_words': 331}