<commit_before>import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | experiments', function (hooks) {
  let experiments
  let storageMock
  let challengeExpectationsMock

  const solvedChallenge = {id: "13"}

  const solvedChallengesFeedbackDisabled = ["13", "14"]

  setupTest(hooks);

  hooks.beforeEach(function () {
    experiments = this.owner.lookup('service:experiments')
    experiments.set('decompositionTreatmentLength', 2)

    storageMock = {
      solvedChallenges: [],
      getSolvedChallenges(){
        return this.solvedChallenges
      }
    }
    experiments.storage = storageMock

    challengeExpectationsMock = {
      _decomposition: true,

      hasDecomposition(){
        return this._decomposition
      }
    }

    experiments.challengeExpectations = challengeExpectationsMock
  })

  //Show non scored expects

  testShouldShowScoredExpectations('control', 'enabled', false)
  testShouldShowScoredExpectations('treatment', 'enabled', true)
  testShouldShowScoredExpectations('treatment', 'disabled', false, solvedChallengesFeedbackDisabled)

  //Show feedback expectations (bubbles)

  testShouldShowBlocksExpectationsFeedback('control', 'enabled', false)
  testShouldShowBlocksExpectationsFeedback('treatment', 'enabled', true)
  testShouldShowBlocksExpectationsFeedback('treatment', 'disabled', false, solvedChallengesFeedbackDisabled)


  //Congratulations modal

  test('Should show congratulations modal - group is not affected', function (assert) {
    experiments.set('group', 'notAffected')
    assert.ok(experiments.shouldShowCongratulationsModal())
  })

  test('Should NOT show congratulations modal - group is affected', function (assert) {
    experiments.set('group', 'treatment')
    assert.notOk(experiments.shouldShowCongratulationsModal())
  })

  //Feedback is disabled
  test('Feedback is disabled - solved challenges longer than decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13", "14", "16"]
    assert.ok(experiments.feedbackIsDisabled())
  })

  test('Feedback is disabled - solved challenges equal decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13", "14"]
    assert.ok(experiments.feedbackIsDisabled())
  })

  test('Feedback is enabled - solved challenges shorter than decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13"]
    assert.notOk(experiments.feedbackIsDisabled())
  })

  //update challenges

  test('Should NOT update solved challenges if challenge was already solved', function (assert){
    storageMock.solvedChallenges = ["13"]
    
    assert.notOk(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  test('Should NOT update solved challenges if challenge does not have decomposition expect', function (assert){
    challengeExpectationsMock._decomposition = false
    assert.notOk(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  test('Should update solved challenges when challenge has decomposition expect and is not already solved', function (assert){
    assert.ok(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  function testShouldShowScoredExpectations(group, feedback, shouldShow, solvedChallenges){
    testShouldShow('scored expects', group, feedback, shouldShow, (() => experiments.shouldShowScoredExpectations()), solvedChallenges)
  }

  function testShouldShowBlocksExpectationsFeedback(group, feedback, shouldShow, solvedChallenges){
    testShouldShow('blocks expectation feedback', group, feedback, shouldShow, (() => experiments.shouldShowBlocksExpectationFeedback()), solvedChallenges)
  }

  function testShouldShow(name, group, feedback, shouldShow, callback, solvedChallenges = []){
    test(`Should ${shouldShow ? "" : "NOT"} show ${name} - ${group} group and feedback ${feedback}`, function(assert){
      storageMock.solvedChallenges = solvedChallenges
      experiments.set('group', group)
      const result = callback()
      if(shouldShow){
        assert.ok(result)
      }else{
        assert.notOk(result)
      }
    })
  }


});




<commit_msg>autoassign tests<commit_after>import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | experiments', function (hooks) {
  let experiments
  let storageMock
  let challengeExpectationsMock
  let pilasBloquesApiMock

  const solvedChallenge = {id: "13"}
  const solvedChallengesFeedbackDisabled = ["13", "14"]

  setupTest(hooks);

  hooks.beforeEach(function () {
    experiments = this.owner.lookup('service:experiments')
    experiments.set('decompositionTreatmentLength', 2)

    storageMock = {
      solvedChallenges: [],
      experimentGroup: "notAffected",
      getSolvedChallenges(){ return this.solvedChallenges },
      getExperimentGroup(){ return this.experimentGroup },
      saveExperimentGroup(){ this.user = {experimentGroup: "treatment"} }
    }
    
    challengeExpectationsMock = {
      _decomposition: true,
      hasDecomposition(){ return this._decomposition }
    }

    pilasBloquesApiMock = {
      user: {experimentGroup: "control"},
      getUser() { return this.user },
      saveExperimentGroup(){ this.user = {experimentGroup: "treatment"} }
    }

    experiments.storage = storageMock
    experiments.challengeExpectations = challengeExpectationsMock
    experiments.pilasBloquesApi = pilasBloquesApiMock
  })

  //Show non scored expects

  testShouldShowScoredExpectations('control', 'enabled', false)
  testShouldShowScoredExpectations('treatment', 'enabled', true)
  testShouldShowScoredExpectations('treatment', 'disabled', false, solvedChallengesFeedbackDisabled)

  //Show feedback expectations (bubbles)

  testShouldShowBlocksExpectationsFeedback('control', 'enabled', false)
  testShouldShowBlocksExpectationsFeedback('treatment', 'enabled', true)
  testShouldShowBlocksExpectationsFeedback('treatment', 'disabled', false, solvedChallengesFeedbackDisabled)


  //Congratulations modal

  test('Should show congratulations modal - group is not affected', async function (assert) {
    experiments.set('group', 'notAffected')
    assert.ok(await experiments.shouldShowCongratulationsModal())
  })

  test('Should NOT show congratulations modal - group is affected', async function (assert) {
    experiments.set('group', 'treatment')
    assert.notOk(await experiments.shouldShowCongratulationsModal())
  })

  //Feedback is disabled
  test('Feedback is disabled - solved challenges longer than decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13", "14", "16"]
    assert.ok(experiments.feedbackIsDisabled())
  })

  test('Feedback is disabled - solved challenges equal decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13", "14"]
    assert.ok(experiments.feedbackIsDisabled())
  })

  test('Feedback is enabled - solved challenges shorter than decompositionTreatmentLength', function (assert) {
    storageMock.solvedChallenges = ["13"]
    assert.notOk(experiments.feedbackIsDisabled())
  })

  //update challenges

  test('Should NOT update solved challenges if challenge was already solved', function (assert){
    storageMock.solvedChallenges = ["13"]
    
    assert.notOk(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  test('Should NOT update solved challenges if challenge does not have decomposition expect', function (assert){
    challengeExpectationsMock._decomposition = false
    assert.notOk(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  test('Should update solved challenges when challenge has decomposition expect and is not already solved', function (assert){
    assert.ok(experiments.shouldUpdateSolvedChallenges(solvedChallenge))
  })

  //autoassign
  test('ExperimentGroup gets group from storage if exists', async function(assert){
    experiments.set('group', 'autoassign')
    assert.deepEqual(await experiments.experimentGroup(), "notAffected")
  })

  test('ExperimentGroup gets group from api if user is logged, has group and group is not in storage', async function(assert){
    experiments.set('group', 'autoassign')
    storageMock.experimentGroup = null
    assert.deepEqual(await experiments.experimentGroup(), "control")
  })

  test('Random experimentGroup is generated when user is NOT logged, and is NOT in storage ', async function(assert){
    experiments.set('group', 'autoassign')
    storageMock.experimentGroup = null
    pilasBloquesApiMock.user = null
    assert.ok(experiments.possibleGroups.includes(await experiments.experimentGroup()))
  })

  test('Random group is saved in api if user is logged and does NOT have a group', async function(assert){
    experiments.set('group', 'autoassign')
    storageMock.experimentGroup = null
    pilasBloquesApiMock.user = {experimentGroup: null}

    assert.ok(experiments.possibleGroups.includes(await experiments.experimentGroup()))
    assert.deepEqual(pilasBloquesApiMock.user.experimentGroup, "treatment")
  })

  function testShouldShowScoredExpectations(group, feedback, shouldShow, solvedChallenges){
    testShouldShow('scored expects', group, feedback, shouldShow, (() => experiments.shouldShowScoredExpectations()), solvedChallenges)
  }

  function testShouldShowBlocksExpectationsFeedback(group, feedback, shouldShow, solvedChallenges){
    testShouldShow('blocks expectation feedback', group, feedback, shouldShow, (() => experiments.shouldShowBlocksExpectationFeedback()), solvedChallenges)
  }

  function testShouldShow(name, group, feedback, shouldShow, callback, solvedChallenges = []){
    test(`Should ${shouldShow ? "" : "NOT"} show ${name} - ${group} group and feedback ${feedback}`, async function(assert){
      storageMock.solvedChallenges = solvedChallenges
      experiments.set('group', group)
      const result = await callback()
      if(shouldShow){
        assert.ok(result)
      }else{
        assert.notOk(result)
      }
    })
  }


});





{'fraction_non_alphanumeric': 0.10600636435958631, 'fraction_numerical': 0.004176610978520286, 'mean_word_length': 4.943853427895981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5701030', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2650, 'n_words': 633}