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

     1  class Notification
     2    attr_reader :title
     3  
     4    def initialize(opts = {})
     5      @title = opts[:title]
     6    end
     7  
     8    def self.doctype
     9      "io.cozy.notifications"
    10    end
    11  
    12    def self.create(inst, at = nil)
    13      msg = Faker::TvShows::Friends.quote
    14      title = Faker::TvShows::DrWho.quote
    15      title = title.gsub(/\W+/, ' ')
    16      attrs = {
    17        category: "balance-lower",
    18        title: title,
    19        message: msg,
    20        content: msg,
    21        content_html: msg
    22      }
    23      attrs[:at] = at unless at.nil?
    24      body = JSON.generate data: { attributes: attrs }
    25      opts = {
    26        accept: "application/vnd.api+json",
    27        authorization: "Bearer #{inst.token_for doctype}"
    28      }
    29      inst.client["/notifications"].post body, opts
    30      Notification.new(title: title)
    31    end
    32  end