<commit_before>// std
import { deepStrictEqual, strictEqual } from 'assert';

// 3p
import { createService } from '@foal/core';
import { sign } from 'jsonwebtoken';

// FoalTS
import { SocialTokens } from './abstract-provider.service';
import { GoogleProvider, InvalidJWTError } from './google-provider.service';

describe('InvalidJWTError', () => {

  it('should have a "message" property.', () => {
    const error = new InvalidJWTError('foobar');

    strictEqual(error.message, 'foobar');
  });

  it('should have a "name" property.', () => {
    const error = new InvalidJWTError();

    strictEqual(error.name, 'InvalidJWTError');
  });

});

describe('GoogleProvider', () => {

  describe('has a "getUserInfoFromTokens" that', () => {

    // TODO: Maybe improve this.
    it('should throw an InvalidJWTError if the id_token is not a valid JWT.', () => {
      const tokens: SocialTokens = {
        access_token: 'xxx',
        id_token: '<PASSWORD>',
        token_type: 'bearer',
      };

      const provider = createService(GoogleProvider);

      try {
        provider.getUserInfoFromTokens(tokens);
        throw new Error('The "getUserInfoFromTokens" method should have thrown an InvalidJWTError.');
      } catch (error) {
        if (!(error instanceof InvalidJWTError)) {<commit_msg>[Social] Use valid base64url encoding in test<commit_after>// std
import { deepStrictEqual, strictEqual } from 'assert';

// 3p
import { createService } from '@foal/core';
import { sign } from 'jsonwebtoken';

// FoalTS
import { SocialTokens } from './abstract-provider.service';
import { GoogleProvider, InvalidJWTError } from './google-provider.service';

describe('InvalidJWTError', () => {

  it('should have a "message" property.', () => {
    const error = new InvalidJWTError('foobar');

    strictEqual(error.message, 'foobar');
  });

  it('should have a "name" property.', () => {
    const error = new InvalidJWTError();

    strictEqual(error.name, 'InvalidJWTError');
  });

});

describe('GoogleProvider', () => {

  describe('has a "getUserInfoFromTokens" that', () => {

    // TODO: Maybe improve this.
    it('should throw an InvalidJWTError if the id_token is not a valid JWT.', () => {
      const tokens: SocialTokens = {
        access_token: 'xxx',
        id_token: 'x.ew.z',
        token_type: 'bearer',
      };

      const provider = createService(GoogleProvider);

      try {
        provider.getUserInfoFromTokens(tokens);
        throw new Error('The "getUserInfoFromTokens" method should have thrown an InvalidJWTError.');
      } catch (error) {
        if (!(error instanceof InvalidJWTError)) {
{'fraction_non_alphanumeric': 0.14654517843583903, 'fraction_numerical': 0.0015186028853454822, 'mean_word_length': 3.4285714285714284, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, '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': '4549736', 'n_tokens_mistral': 788, 'n_tokens_neox': 771, 'n_words': 206}