<commit_before>// tslint:disable:no-empty

import { Config, Credentials, DynamoDB } from 'aws-sdk'
import { EMPTY, Observable } from 'rxjs'
import { DEFAULT_SESSION_VALIDITY_ENSURER } from './default-session-validity-ensurer.const'
import { DynamoRx } from './dynamo-rx'
import { SessionValidityEnsurer } from './session-validity-ensurer.type'

describe('dynamo rx', () => {


  describe('should call the validity ensurer before each call and return an observable', () => {
    let dynamoRx: DynamoRx
    let spyValidityEnsurer: SessionValidityEnsurer

    beforeEach(() => {
      spyValidityEnsurer = jasmine.createSpy().and.returnValue(EMPTY)
      dynamoRx = new DynamoRx(spyValidityEnsurer)
    })

    it('putItem', () => {
      expect(dynamoRx.putItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('getItem', () => {
      expect(dynamoRx.getItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('updateItem', () => {
      expect(dynamoRx.updateItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('deleteItem', () => {
      expect(dynamoRx.deleteItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('batchWriteItem', () => {
      expect(dynamoRx.batchWriteItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('batchGetItems', () => {
      expect(dynamoRx.batchGetItems(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('scan', () => {
      expect(dynamoRx.scan(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('query', () => {
      const params: DynamoDB.QueryInput = {
        TableName: 'tableName',
      }
      expect(dynamoRx.query({ ...params, KeyConditionExpression: 'blub' }) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
      expect(() => dynamoRx.query(params)).toThrow()
    })
    it('makeRequest', () => {
      expect(dynamoRx.makeRequest(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
  })

  it('should update the credentials', () => {
    const dynamoRx = new DynamoRx(DEFAULT_SESSION_VALIDITY_ENSURER)
    const credentials = new Credentials({ secretAccessKey: '', sessionToken: '', accessKeyId: '' })
    dynamoRx.updateAwsConfigCredentials(new Config({ credentials }))
    expect(dynamoRx.dynamoDb.config.credentials).toBe(credentials)
  })

  xit('should use the given aws region', () => {})

})<commit_msg>test(dynamo-rx): add test for makeRequest<commit_after>// tslint:disable:no-empty
// tslint:disable:no-unnecessary-callback-wrapper

import { Config, Credentials, DynamoDB } from 'aws-sdk'
import { EMPTY, Observable } from 'rxjs'
import { DEFAULT_SESSION_VALIDITY_ENSURER } from './default-session-validity-ensurer.const'
import { DynamoRx } from './dynamo-rx'
import { SessionValidityEnsurer } from './session-validity-ensurer.type'

describe('dynamo rx', () => {
  
  describe('should call the validity ensurer before each call and return an observable', () => {
    let dynamoRx: DynamoRx
    let spyValidityEnsurer: SessionValidityEnsurer

    beforeEach(() => {
      spyValidityEnsurer = jasmine.createSpy().and.returnValue(EMPTY)
      dynamoRx = new DynamoRx(spyValidityEnsurer)
    })

    it('putItem', () => {
      expect(dynamoRx.putItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('getItem', () => {
      expect(dynamoRx.getItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('updateItem', () => {
      expect(dynamoRx.updateItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('deleteItem', () => {
      expect(dynamoRx.deleteItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('batchWriteItem', () => {
      expect(dynamoRx.batchWriteItem(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('batchGetItems', () => {
      expect(dynamoRx.batchGetItems(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('scan', () => {
      expect(dynamoRx.scan(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
    it('query', () => {
      const params: DynamoDB.QueryInput = {
        TableName: 'tableName',
      }
      expect(dynamoRx.query({ ...params, KeyConditionExpression: 'blub' }) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
      expect(() => dynamoRx.query(params)).toThrow()
    })
    it('makeRequest', () => {
      expect(dynamoRx.makeRequest(<any>null) instanceof Observable).toBeTruthy()
      expect(spyValidityEnsurer).toHaveBeenCalled()
    })
  })

  it('should call makeRequest with the given params', async () => {
    const dynamoRx = new DynamoRx(DEFAULT_SESSION_VALIDITY_ENSURER)
    const makeRequest = jasmine.createSpy().and.returnValue({ promise: () => Promise.resolve(null) })
    Object.assign(dynamoRx, { dynamoDb: { makeRequest } })

    await dynamoRx.makeRequest(<any>{ ok: true }).toPromise()
    expect(makeRequest).toHaveBeenCalled()
    expect(makeRequest.calls.mostRecent().args[0]).toEqual({ ok: true })
  })

  it('should update the credentials', () => {
    const dynamoRx = new DynamoRx(DEFAULT_SESSION_VALIDITY_ENSURER)
    const credentials = new Credentials({ secretAccessKey: '', sessionToken: '', accessKeyId: '' })
    dynamoRx.updateAwsConfigCredentials(new Config({ credentials }))
    expect(dynamoRx.dynamoDb.config.credentials).toBe(credentials)
  })

  xit('should use the given aws region', () => {})

})
{'fraction_non_alphanumeric': 0.14564052605942523, 'fraction_numerical': 0.0001623640201331385, 'mean_word_length': 4.260461144321093, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 52, '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': '5422235', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1984, 'n_words': 296}