github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/tests/system/lib/account.rb (about)

     1  class Account
     2    include Model
     3  
     4    attr_reader :name, :log
     5  
     6    def self.doctype
     7      "io.cozy.accounts"
     8    end
     9  
    10    def initialize(opts = {})
    11      @couch_id = opts[:id]
    12      @name = (opts[:name] || Faker::TvShows::DrWho.character).gsub(/[^A-Za-z0-9]/, '_')
    13      @log = opts[:log] || "#{Helpers.current_dir}/account_#{@name}.log"
    14      @aggregator = opts[:aggregator]
    15      @failure = opts[:failure]
    16      @type = opts[:type]
    17      @auth = opts[:auth]
    18      @webdav_user_id = opts[:webdav_user_id]
    19    end
    20  
    21    def as_json
    22      json = {
    23        name: @name,
    24        data: {
    25          log: @log,
    26          failure: @failure
    27        },
    28        account_type: @type,
    29        auth: @auth,
    30        webdav_user_id: @webdav_user_id
    31      }.compact
    32      if @aggregator
    33        json[:relationships] = {
    34          data: {
    35            _id: @aggregator.couch_id,
    36            _type: @aggregator.doctype
    37          }
    38        }
    39      end
    40      json
    41    end
    42  end